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

def solve(n,k):

#    print("solve",n,k)

    if n<10**5:
        ans=0
        for num in range(1,n+1):
            cnt=0
            for char in str(num):
                if char!="0":
                    cnt+=1
            if cnt==k:
                ans+=1
        return ans

    keta = len(str(n))
    max_num=int(str(n)[0])

    if k==1:
        return max_num + 9*(keta-1)

    if n==max_num*(10**(keta-1)):
        if k==2:
            ans=max_num*(keta-1)*9
            return ans + solve(10**(keta-1) - 1,2)
        if k==3:
            ans=max_num*(keta-1)*(keta-2)/2 * 81
            return ans + solve(10**(keta-1) - 1,3)

    return solve(max_num*(10**(keta-1)),k)+solve(n-max_num*(10**(keta-1)),k-1)

print(solve(n,k))