#include <bits/stdc++.h>
using namespace std;

int main(){
  int E, Y , Y2;
  cin >> E >> Y;
  if(E == 0){
    if(1868 <= Y && Y <= 1911){ Y2 = Y - 1867;
      cout << "M" << Y2 << endl;}
    if(1912 <= Y && Y <= 1925){ Y2 = Y - 1911;
      cout << "T" << Y2 << endl;}
    if(1926 <= Y && Y <= 1988){ Y2 = Y - 1925; 
      cout << "S" << Y2 << endl;}
    if(1989 <= Y && Y <= 2016){ Y2 = Y - 1988;
      cout << "H" << Y2 << endl;}
  }

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

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

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

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

}

   
  




 
