If you don't intend to make some operation with text the sed usage seems is more resonable
sed -En 's/.* (\S+)M$/\1/p'
-E let's to avoid meta-characters usage with backslash (\(, \+, etc.)
-n suppress output exept ordered by p
s/ substitute
.* first part of the line for space (the last space becouse greadygreedy)
() "revers link" - you can call pattern inside brackets by \number
\S every non-space simbol (everything exept :blank:)
+ one or more previous simbol
M$ "M" at the end of line
/p print line where substitution is made
Meaning is "Substitute whole line by pattern inside brackets and print lines where such substitution is made only"