#include<iostream>
#include<cstdio>
using namespace std;
int main(void)
{
	int E,Y,a;
	cin>>E>>Y;
	if(E==0){
		if(2016>=Y && Y>=1989){
			a=28-(2016-Y);
			printf("H%d\n",a);
		}
		else if(1988>=Y && Y>=1926){
			a=63-(1988-Y);
			printf("S%d\n",a);
		}
		else if(1925>=Y && Y>=1912){
			a=14-(1925-Y);
			printf("T%d\n",a);
		}
		else{
			a=44-(1911-Y);
			printf("M%d\n",a);
		}
	}
	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;
	return 0;
}
