#include <iostream>

using namespace std;

int main(void){
  int e,y;
  int dict[] = {1868, 1912, 1926, 1989};
  
  cin >> e >> y;
  if (e){ // Jap -> Euro
    cout << (dict[e-1]+y-1) << endl;
  } else { // Euro -> Jap
    for (int i=3; i>=0; i--){
      if (y>=dict[i]){
        cout << "MTSH"[i] << (y-dict[i]+1) << endl;
        break;
      }
    }
  }
  
  return 0;
}
  
