from math import factorial
N=int(input())
K=int(input())
S = list(map(int,str(N))) #桁数
ans = 0
k = K
l = len(S) #桁数

def C(n,r): #組み合わせ
    if n >= r:
        return factorial(n) // (factorial(n - r) * factorial(r))
    else:
        return 0

def D(i,j): 
    return (9**j)*C(i,j)

if K > len(S):
    print(0)
    exit()

for i in range(l):
    if k > 1:
        if int(S[i]) != 0:
            ans = ans + (int(S[i])-1)*D(l-1,k-1) + D(l-1,k)
            k -= 1
            l -= 1
        else:
            if K == len(S):
                print(0)
                exit()
            else:
                l -= 1
    elif k == 1:
        ans = ans + int(S[i]) + D(l-1,k)
        k -= 1
        l -= 1
    else:      
        break

print(ans)

