#include <iostream>
using namespace std;
int main(void){
  int E,Y;
  cin >> E >> Y;
  if(E==0){
      if(1868 <= Y && Y <= 1911){
          cout << "M" << Y-1868+1  << endl;
      }
      else if(1912 <= Y && Y <= 1925){
          cout << "T" << Y-1912+1 << endl;
      }
      else if(1926 <= Y && Y <= 1988){
          cout << "S" << Y-1926+1 << endl;
      }
      else if(1989 <= Y && Y <= 2016){
          cout << "H" << Y-1989+1 << endl;
      }
  }
  else if(E==1){
      cout << 1868+Y-1 << endl;
  }
  else if(E==2){
      cout << 1868+44+Y-1 << endl;
  }
  else if(E==3){
      cout << 1868+44+14+Y-1 << endl;
  }
  else if(E==4){
      cout << 1868+44+14+63+Y-1 << endl;
  }
}
