// Name: Jason Cobb
// Grade: 11
// Division: I-3
// School: Triangle Math and Science Academy

import kotlin.math.abs

private fun Char.parseDigit(): Int {
    val i = "$this".toInt()
    check(0 <= i && i < 10)
    return i
}

private fun doDigitTransform(string: String, charMap: (Int) -> Int): String {
    return string.map { it.parseDigit() }.map(charMap).map { it.toString().last() }.joinToString("")
}

fun main() {
    repeat(5) { _ ->
        try {
            val line = readLine()!!
            val (N, strP) = line.split(" ").filter { it.isNotBlank() }

            val pRightIndex = strP.toInt()
            val pIndex = N.length - pRightIndex
            val pValue = N[pIndex].parseDigit()

            val initialNLeft = N.substring(0, pIndex)
            val initialNRight = N.substring(pIndex + 1, N.length)

            val newNRight = doDigitTransform(initialNLeft) { it + pValue }
            val newNLeft = doDigitTransform(initialNRight) { abs(it - pValue) }

            println(newNRight + pValue + newNLeft)
        } catch (throwable: Throwable) {
            throwable.printStackTrace()
        }
    }
}