#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int e,y;
 int ans=0;
  cin>>e>>y;
  if(e==0){
    if(y<=1911){
      cout<<"M";
      ans=y-1867;
    }
    else if(y<=1925){
      cout<<"T";
      ans=y-1911;
    }
     else if(y<=1988){
      cout<<"S";
      ans=y-1925;
    }
     else{
      cout<<"H";
      ans=y-1988;
    }
    cout<<ans<<"\n";
  }
  else{
    if(e==1){
      ans=1867+y;
    }
    else if(e==2){
      ans=1911+y;
    }
    else if(e==3){
      ans=1925+y;
    }
    else{
      ans=1988+y;
    }
    cout<<ans<<"\n";
  }

  return 0;
}


