Spectral M-estimation with Applications to Hidden Markov Models