M1 is amakes the code "non-cumulative" code which means- they just tax your pay on the basis of the current month's allowances and nothing elseon the basis of the current month's allowances and nothing else.
As well as the tax-free allowance, that also means that you only get 1 months' worth of the 20% band. The annual allowances for this year are that anything below £11,850 is tax-free, and anything above this and below £46,350 is taxed at 20%. So on a monthly basis, anything above ~£4,000 would be taxed at 40%.
If you can't get it sorted out now, at the latest you can deal with it at the end of the tax year by contacting HMRC and asking them to recalculate your full year's tax. Or before that your next job should put you on a normal cumulative tax code which means they'll look at your year-to-date earnings and your tax paid to date, and withhold less tax from you than normal until the two are back in sync.
It's strange that you have the M1 code at all though, assuming you didn't have it in previous months.