#include <iostream>
using namespace std;
int main(){
    int n,z;cin>>n>>z;
    if(n){
        if(n==1){
            cout << 1867+z << endl;
        }else if(n==2){
            cout << 1911+z << endl;
        }else if(n==3){
            cout << 1925+z << endl;
        }else{
            cout << 1988+z << endl;
        }
    }else{
        if(z < 1912){
            cout << "M" << z-1867 << endl;
        }else if(z < 1926){
            cout << "T" << z-1911 << endl;
        }else if(z < 1989){
            cout << "S" << z-1925 << endl;
        }else{
            cout << "H" << z-1988 << endl;
        }
    }
}
