#include <bits/stdc++.h>
using namespace std;

char str[4] = {'M', 'T', 'S', 'H'};
int d[5] = {44, 14, 63, 28, 0};
int main(){
	int c, x, ans = 0, t = 1911;
	scanf("%d%d", &c, &x);
	if(!c){
		int i = 0;
		for(i;i < 4;i++){
			if(x <= t)break;
			t += d[i+1];
		}
		printf("%c%d\n", str[i], d[i]-(t-x));
	}else{
		for(int i = 0;i != c-1;i++)ans += d[i];
		printf("%d\n", ans+1868+x-1);
	}
	return 0;
}
