e, y = gets.chomp.split.map(&:to_i)
year = nil
case e
when 0
    if y < 1912
        year = "M" + (y - 1867).to_s
    elsif y < 1926
        year = "T" + (y - 1911).to_s
    elsif y < 1989
        year = "S" + (y - 1925).to_s
    else
        year = "H" + (y - 1988).to_s
    end
when 1
    year = y + 1867
when 2
    year = y + 1911
when 3
    year = y + 1925
when 4
    year = y + 1988
end
puts year

