#include<iostream>
using namespace std;
int main()
{
	int E, Y;
	cin >> E >> Y;
	if (E == 0)
	{
		if (Y <= 1911)
			cout << 'M' << Y - 1867 << endl;
		else if (Y <= 1925)
			cout << 'T' << Y - 1911 << endl;
		else if (Y <= 1988)
			cout << 'S' << Y - 1925 << endl;
		else if (Y <= 2016)
			cout << 'H' << Y - 1988 << endl;
	}
	else if (E == 1)
		cout << Y + 1867 << endl;
	else if (E == 2)
		cout << Y + 1911 << endl;
	else if (E == 3)
		cout << Y + 1925 << endl;
	else if (E == 4)
		cout << Y + 1988 << endl;
	return 0;
}