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

def nCk(N, K):
    if K > n or K < 0:
        return 0
    return fact[N] // fact[K] // fact[N-K]


def digits(N):
    N = abs(N)
    ret = 0
    x = 1
    while x <= N:
        ret += 1
        x *= 10
    return ret

fact = [1]
for i in range(1, 101):
    fact += [fact[i-1] * i]

digit = digits(n)
ans = 0
k9 = 9 ** k
for i in range(k, digit):
    ans += k9 * nCk(i - 1, k - 1)
ans += (n // (10**(digit-1)) - 1) * (k9//9) * nCk(digit-1, k-1)

if k == 1:
    print(ans+1)
    exit()
elif k == 2:
    n10 = n%(10**(digit-1))
    if n10 == 0:
        print(ans)
        exit()
    d = digits(n10)
    top = n10 // (10**(d-1))
    print(ans + top + 9 * (d-1))
elif k == 3:
    n10 = n%(10**(digit-1))
    if n10 == 0:
        print(ans)
        exit()
    d10 = digits(n10)
    n100 = n10%(10**(d10-1))
    if n100 == 0:
        top = n10 // (10**(d10-1))
        print(ans + (top-1) * 9 * (d10-1))
        exit()
    d100 = digits(n100)
    top = n10 // (10**(d10-1))
    sec = n100 // (10**(d100-1))
    print(ans + sec + (top-1)*9*(d10-1) + 9 * 9 * nCk(d10-1, 2))
