//John Kesler
//Cary Academy INT-3
//ACSL Contest #1

inputs = [[int(j) for j in i.strip().split(" ")] for i in open("input.txt").readlines()]

def run_case(i):
    n, p = i
    digits = [int(j) for j in str(n)]
    p = len(digits) - p
    val = digits[p]
    for i in range(p):
        digits[i] = (digits[i] + val) % 10
    for i in range(p+1, len(digits)):
        digits[i] = abs(digits[i] - val) % 10
    return "".join([str(i) for i in digits])

print("\n".join([str(run_case(i)) for i in inputs]))