P,N = input().split() import sys if N == "0": print(P) exit() d = [6,2,5,5,4,5,6,4,7,6] ans = 0 if P[0] == "-": ans += 1 P = P[1:] for p in P: ans += d[int(p)] if len(N) >= 4: N = 1000 else: N = int(N) - 1 def calc(S): tmp = 0 while S: tmp += d[S % 10] S //= 10 return tmp for _ in range(N): ans = calc(ans) print(ans)