e, y = gets.split.map(&:to_i)
case e
when 0
  if y <= 1911
    puts "M#{y - 1867}"
  elsif y <= 1925
    puts "T#{y - 1911}"
  elsif y <= 1988
    puts "S#{y - 1925}"
  else
    puts "H#{y - 1988}"
  end
when 1 then puts 1867 + y
when 2 then puts 1911 + y
when 3 then puts 1925 + y
when 4 then puts 1988 + y
end

