def calculate(number, index):
    answer=""
    index=len(number)-index
    prime=int(number[index])
    for i in range(index):
        num=int(number[i])+prime
        answer+=str(num)
    fact=numOfDistinctPF(int(number))
    answer+=str(fact)
    for i in range(index+1,len(number)):
        num=abs(int(number[i])-prime)
        answer+=str(num)
    return answer

def numOfDistinctPF(number):
    count=0
    for num in range(2,int((number+1)**0.5)):
        if number%num==0:
            count+=1
            while number%num==0:
                number=number/num
    if number>1:
        count+=1
    return count

import sys
lines=sys.stdin.read().strip().split("\n")
for i in range(len(lines)):
    line=lines[i].split()
    number, index=line[0],int(line[1])
    print(calculate(number,index))