#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main(){
	int a, b; cin >> a >> b;
	
	if(a == 1) cout << 1867 + b << endl;
	else if(a == 2) cout << 1911 + b << endl;
	else if(a == 3) cout << 1925 + b << endl;
	else if(a == 4) cout << 1988 + b << endl;
	else {
		if(b < 1912) cout << "M" << b - 1867 << endl;
		else if(b < 1926) cout << "T" << b - 1911 << endl;
		else if(b < 1989) cout << "S" << b - 1925 << endl;
		else cout << "H" << b - 1988 << endl;
	}
	return 0;
}

