D = [6,2,5,5,4,5,6,4,7,6] def f(x): if 0 <= x and x < 10: return D[x] if 10 <= x: r = 0 s = str(x) for i in s: r += f(int(i)) return r return 1 + f(-x) P,N = list(map(int,input().split())) assert -10**200000 <= P <= 10**200000 assert 0 <= N <= 10**200000 N = min(30,N) ans = P for i in range(N): ans = f(ans) print(ans)