import math

N = int(input())
K = int(input())

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

ans = 0
for i in range(1, len(str(N))):
    if i < K:
        continue
    ans += comb(i-1, K-1) * 9**K

for i in range(9):
    i = 9 - i
    num = i * 10**(len(str(N))-1)
    if num > N:
        continue
    ans += comb(len(str(N))-1, K-1) * 9**(K-1) * (i-1)
    break

if K == 1:
    if num <= N:
        ans += 1

if K == 2:
    for i in range(len(str(N))-1):
        for j in range(1, 10):
            num2 = num + j * 10**i
            if num2 <= N:
                ans += 1

if K == 3:

    for i in range(99):
        i = 99 - i
        num = i * 10**(len(str(N))-2)
        if num > N:
            continue
        ans += comb(len(str(N))-2, K-2) * 9**(K-2) * (i-1)
        break

    for i in range(len(str(N))-2):
        for j in range(1, 10):
            num2 = num + j * 10**i
            if num2 <= N:
                ans += 1

print(ans)