#include<bits/stdc++.h>
#define LL long long int
using namespace std;
int main(void)
{
	int e,y;
	cin>>e>>y;
	if(e==0) {
		if(1911>=y) cout<<"M"<<(y-1868)+1<<endl;
		else if(1925>=y) cout<<"T"<<(y-1912)+1<<endl;
		else if(1988>=y) cout<<"S"<<(y-1926)+1<<endl;
		else cout<<"H"<<(y-1989)+1<<endl;
	}
	else {
		if(e==1) cout<<(1868+y)-1<<endl;
		else if(e==2) cout<<(1912+y)-1<<endl;
		else if(e==3) cout<<(1926+y)-1<<endl;
		else cout<<(1989+y)-1<<endl;
	}
}