def main(): import sys sys.setrecursionlimit(1 << 25) N, M = map(int, sys.stdin.readline().split()) if M >= 9: print(0) return s = str(N) len_n = len(s) memo = {} def dp(pos, tight, max_so_far, leading_zero): if pos == len_n: return 1 key = (pos, tight, max_so_far, leading_zero) if key in memo: return memo[key] limit = int(s[pos]) if tight else 9 total = 0 for d in range(0, limit + 1): new_tight = tight and (d == limit) if leading_zero: if d == 0: new_leading_zero = True new_max = max_so_far else: new_leading_zero = False new_max = d else: new_leading_zero = False new_max = max(max_so_far, d) if not leading_zero and new_max > M: continue total += dp(pos + 1, new_tight, new_max, new_leading_zero) memo[key] = total return total x = dp(0, True, -1, True) answer = (N + 1) - x print(answer) if __name__ == "__main__": main()