import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = input()
k = int(input())

def calc(i, k):
    return comb(len(n) - i - 1, k) * 9 ** k

def cnt(n):
    ret = 0
    for c in n:
        if c != '0':
            ret += 1
    return ret

ans = 0

for i in range(min(len(n), k)):
    if int(n[i]) == 0:
        continue
    if len(n)-i > k:
        ans += calc(i, k)
    k -= 1
    if len(n)-i > k:
        ans += (int(n[i]) - 1) * calc(i, k)
    if k == 0:
        ans += 1
print(ans)
