#include <bits/stdc++.h>

using namespace std;

int main()
{
    int E, Y;
    const int p[5] = {1868, 1912, 1926, 1989, 2017};
    const char q[4] = {'M', 'T', 'S', 'H'};
    cin >> E >> Y;
    if (E == 0) {
        for (int i = 0; i < 4; i++) {
            if (p[i] <= Y && Y < p[i+1]) {
                cout << q[i] << Y - p[i] + 1 << endl;
                break;
            }
        }
    } else {
        cout << p[E-1] + Y - 1 << endl;
    }        
    return 0;
}