I think so because the rank 1 of unofficials code seem to be wrong(if I don't misunderstand the meaning of problem).
we can test the following data:
7 8
1 2 M
1 4 M
3 4 M
7 6 M
2 4 S
1 3 S
3 5 S
4 6 S
the output of his code is -1.
but I think
6
1 2 4 6 7 8
is one of possible solution.
I think this input should somehow be tested with the official solution, to check if it's only a missing test case among the ones used during the contest or if the solution itself is wrong (maybe some test case actually used covers this case?). When this is the case, they usually make the contest unrated...
ED: Nevermind, there're others accepted codes that handle this case correctly. It's just a missing test case. That first code, however, is still wrong.