""" """ import sys from sys import stdin lis = [6,2,5,5,4,5,6,4,7,6] def f(x): if type(x) == type(lis): ret = 0 for i in x: if i == "-": ret += 1 else: ret += lis[int(i)] return ret else: ret = 0 if x < 0: ret += 1 x *= -1 while x > 0: ret += lis[x % 10] x //= 10 return ret P,N = stdin.readline().split() if len(N) >= 1000: N = float("inf") else: N = int(N) if len(P) < 100: P = int(P) while (type(P) != type(lis) and not(4 <= P <= 6)) and N > 0: P = f(P) N -= 1 print (P)