#include<iostream>
using namespace std;

int main(){
    int e,y;
    cin>>e>>y;
    char jp;
    int ans;

    if(e==0){
        
        if(y<=1911){
            jp='M';
            ans=y-1867;
        }else if(y<=1925){
            jp='T';
            ans=y-1911;
        }else if(y<=1988){
            jp='S';
            ans=y-1925;
        }else if(y<=2016){
            jp='H';
            ans=y-1988;
        }
        cout<<jp;

    }else if(e==1){
        ans = y+1867;
    }else if(e==2){
        ans=y+1911;
    }else if(e==3){
        ans=y+1925;
    }else if(e==4){
        ans=y+1988;
    }




    cout<<ans<<endl;

    return 0;
}

