P, N = map(str, input().split()) def f(x): if x==0 or x==6 or x==9: return 6 elif x==1: return 2 elif x==2 or x==3 or x==5: return 5 elif x==4 or x==7: return 4 elif x == 8: return 7 elif x >= 10: return f(x//10) + f(x%10) if N == '0': print(P) exit() x = 0 N = int(N) - 1 if P[0] == '-': P = P[1:] x = 1 for p in P: x += f(int(p)) if N == 0: print(x) exit() P = x for i in range(N): P = f(P) if 4<=P<=6: print(P) exit() else: print(P) exit()