#include <iostream>
using namespace std;
int main(){
    int e,y;
    cin>>e>>y;
    if(e==0){
        if(1868<=y&&y<1912){
            cout<<"M"<<y-1868+1<<endl;
        }else if(1912<=y&&y<1926){
            cout<<"T"<<y-1912+1<<endl;
        }else if(1926<=y&&y<1989){
            cout<<"S"<<y-1926+1<<endl;
        }else{
            cout<<"H"<<y-1989+1<<endl;
        }
    }else if(e==1){
        cout<<y+1868-1<<endl;
    }else if(e==2){
        cout<<y+1912-1<<endl;
    }else if(e==3){
        cout<<y+1926-1<<endl;
    }else{
        cout<<y+1989-1<<endl;
    }
}