def f(x): if x==0: return 6 elif x==1: return 2 elif x==2: return 5 elif x==3: return 5 elif x==4: return 4 elif x==5: return 5 elif x==6: return 6 elif x==7: return 4 elif x==8: return 7 elif x==9: return 6 elif x>=10: return f(x//10)+f(x%10) else: return 1+f(-x) def g(S): if S[0]=="-": S=S[1:] X=1 else: X=0 for s in S: X+=f(int(s)) return X P,N=input().split() if N=="0": print(P) exit() N=int(N) P=g(P) N-=1 while N: N-=1 P=f(P) if 4<=P<=6: break print(P)