#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	int e,y;
	cin>>e>>y;
	switch(e){
	case 0:
		if(1868<=y&&y<=1911)
			cout<<'M'<<y-1867<<endl;
		else if(1912<=y&&y<=1925)
			cout<<'T'<<y-1911<<endl;
		else if(1826<=y&&y<=1988)
			cout<<'S'<<y-1925<<endl;
		else if(1989<=y&&y<=2016)
			cout<<'H'<<y-1988<<endl;
		break;
	case 1:
		cout<<y+1867<<endl;
		break;
	case 2:
		cout<<y+1911<<endl;
		break;
	case 3:
		cout<<y+1925<<endl;
		break;
	case 4:
		cout<<y+1988<<endl;
		break;
	}
	return 0;
}