#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)

int s[] = {1868, 1912, 1926, 1989};
string t = "MTSH";
int e, y;

int main() {
  cin.tie(0); ios_base::sync_with_stdio(0);

  cin >> e >> y;
  if (e) {
    cout << s[e-1] + y - 1 << "\n";
  } else {
    repr(i, 4) if (y >= s[i]) {
      cout << t[i] << y - s[i] + 1 << "\n";
      break;
    }
  }
}
