#include <iostream>
using namespace std;;

int main(){
int E,Y;
cin>>E>>Y;

if(E==0 && 1989 <= Y) cout<<"H"<<Y-1989+1<<endl; 
if(E==0 && 1926 <= Y && Y <=1988) cout<<"S"<<Y-1926+1<<endl;
if(E==0 && 1912 <= Y && Y <=1925) cout<<"T"<<Y-1912+1<<endl;
if(E==0 && 1868 <= Y && Y <=1911) cout<<"M"<<Y-1868+1<<endl;


if(E==1) cout<<Y+1868-1<<endl;
if(E==2) cout<<Y+1912-1<<endl;
if(E==3) cout<<Y+1926-1<<endl;
if(E==4) cout<<Y+1989-1<<endl;

return 0;
}

