p, n = input().split() add = 0 if p[0] == '-': add += 1 p = p[1:] P = [int(i) for i in p] P[0] += add m = len(P) idx = m - 1 while idx > 0 and P[idx] == 10: P[idx] = 0 idx -= 1 P[idx] += 1 if P[0] == 10: P[0] = 0 P = [1] + P m += 1 def change_digit(P): for i in range(len(P)): if P[i] == 1: P[i] = 2 elif P[i] == 2 or P[i] == 3: P[i] = 5 elif P[i] == 0 or P[i] == 9: P[i] = 6 elif P[i] == 8: P[i] = 7 elif P[i] == 7: P[i] = 4 return P cnt = 0 while n != str(cnt): cnt += 1 P = change_digit(P) sumP = str(sum(P)) P = [int(i) for i in sumP] if len(P) == 1: if P[0] in (4, 5, 6): break print(''.join(map(str, P)))