#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) a = b;
  return a > b;
}
template<class T> inline bool chmax(T&a, T b) {
  if (a < b) a = b;
  return a < b;
}

signed main() {
  int E, Y;
  cin >> E >> Y;
  int a[4] = { 1989, 1926, 1912, 1868 };
  char b[4] = { 'H', 'S', 'T', 'M' };
  if (E == 0) {
    for (int i = 0; i < 4; i++) {
      if (Y-a[i]+1 > 0) {
        cout << b[i] << Y-a[i]+1 << endl;
        break;
      }
    }
  } else {
    cout << Y+a[4-E]-1 << endl;
  }
}

