import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(2*10**5+10) write = lambda x: sys.stdout.write(x+"\n") debug = lambda x: sys.stderr.write(x+"\n") p,n = input().split() n = int(n) l = [6,2,5,5,4,5,6,4,7,6] if n==0: write(p) else: n -= 1 if p[0]=="-": v = sum((l[v] for v in map(int, p[1:]))) + 1 else: v = sum((l[v] for v in map(int, p))) res = [] for _ in range(10000): res.append(v) v = sum((l[int(vv)] for vv in str(v))) if n>=len(res): print(res[-1]) else: print(res[n])