x = input() m = int(input()) iflen(x) == 1: ifint(x) <= m: print(1) else: print(0) sys.exit(0) len = len(x)
defcheck(n): sum = 0 for j inrange(0, len): ss = 1 for k inrange(0, len - j - 1): ss *= n if ss > m: return1 sum += ss * (ord(x[j]) - ord('0')) ifsum > m: return1 return0
d = 0 ans = 0 for i in x: d = max(d, ord(i) - ord('0') + 1)
l = d r = 10 ** 18 + 1 while l <= r: mid = (l + r) // 2 if check(mid): r = mid - 1 else: l = mid + 1 print(r - d + 1)