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

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