#include<iostream>
using namespace std;

int main(){
  int E,Y;
  cin >> E >> Y;

  if(E==0){
    if(Y<1912)
      cout << "M" << Y-1867 << endl;
    else if(Y<1926)
      cout << "T" << Y-1911 << endl;
    else if(Y<1989)
      cout << "S" << Y-1925 << endl;
    else
      cout << "H" << Y-1988 << endl;
  }

  if(E==1)
    cout << Y+1867 << endl;

  if(E==2)
    cout << Y+1911 << endl;

  if(E==3)
    cout << Y+1925 << endl;

  if(E==4)
    cout << Y+1988 << endl;

  return 0;
}
