dat=[6,2,5,5,4,5,6,4,7,6] def f(x): ans=0 for c in str(X): if c=='-': ans+=1 else: ans+=dat[ord(c)-48] count=[0 for i in range(1400000)] P,N=map(int,input().split()) if N==0: print(P) else: P=f(P) cnt=1 L=[0] while count[P]==0: count[P]=cnt if cnt==N: print(P) break L+=[P] cnt+=1 P=f(P) else: print(L[count[P]+(N-count[P])%(cnt-count[P])])