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