seg_cnt = [6, 2, 5, 5, 4, 5, 6, 4, 7, 6] def f(x): if x == 0: return 6 ret = 0 if x < 0: x = -x ret += 1 while x: x, d = divmod(x, 10) ret += seg_cnt[d] return ret P_str, N_str = input().split() if N_str == '0': print(P_str) exit() P = 0 for c in P_str: P += 1 if c == '-' else seg_cnt[ord(c) - 48] N = (int(N_str) if len(N_str) <= 2 else 100) - 1 for _ in range(N): P = f(P) if 4 <= P <= 6: break print(P)