Marks and Spencer (M&S) has warned investors it is facing a £300m hit to trading profits as a result of last month's ransomware attack.