fun main(args: Array<String>) {
    val (e, y) = readLine()!!.split(" ").map { it.toInt() }
    println(
        when (e) {
            0 -> toWareki(y)
            1 -> 1868 + y - 1
            2 -> 1912 + y - 1
            3 -> 1926 + y - 1
            4 -> 1989 + y - 1
            else -> throw IllegalArgumentException()
        }
    )
}

fun toWareki(y: Int) = when (y) {
    in 1868..1911 -> "M${y - 1868 + 1}"
    in 1912..1925 -> "T${y - 1912 + 1}"
    in 1926..1988 -> "S${y - 1926 + 1}"
    in 1989..2016 -> "H${y - 1989 + 1}"
    else -> throw IllegalArgumentException()
}
