p,n=input().split() ans=0 if p[0]=="-": ans+=1 p=p[1:] num=[6,2,5,5,4,5,6,4,7,6] if n=="0": print(p) else: memo=[] for i in range(10): for j in range(len(p)): ans+=num[int(p[j])] memo.append(ans) p=str(ans) ans=0 if int(n)<=10: print(memo[int(n)-1]) else: seen=[False]*(2*10**6) memo2=[] for i in range(2*10**6): for j in range(len(p)): ans+=num[int(p[j])] if seen[ans]==True: break memo2.append(ans) seen[ans]=True p=str(ans) ans=0 print(memo2[(int(n)-10)%len(memo2)])