#include <iostream>
using namespace std;
signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int e,y;
    cin>>e>>y;
    if(e==0){
        if(y<=1911){
            cout<<"M"<<y-1867<<"\n";
        }
        if(y>=1912 && y<=1925){
            cout<<"T"<<y-1911<<"\n";
        }
        if(y>=1926 && y<=1988){
            cout<<"S"<<y-1925<<"\n";
        }
        if(y>=1989){
            cout<<"H"<<y-1988<<"\n";
        }
    }
    if(e==1){
        cout<<y+1867<<"\n";
    }
    if(e==2){
        cout<<y+1911<<"\n";
    }
    if(e==3){
        cout<<y+1925<<"\n";
    }
    if(e==4){
        cout<<y+1988<<"\n";
    }
    return 0;
}

