#include <iostream>
using namespace std;

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