def seg(x): if x[0] == "-": return 1 + seg(x[1:]) elif len(x) >= 2: return sum(seg(i) for i in x) else: return [6, 2, 5, 5, 4, 5, 6, 4, 7, 6][int(x)] p, n = input().split() now = p if len(n) > 10: n = 10 for i in range(int(n)): now = str(seg(now)) print(now)