
def solve(p,n,k):
    if k==1:
        return 10 + 9*(n-1)+(p-1)
    elif k==2:
        return 81 * n*(n-1)//2 + (p-1)*9*n
    else:
        return 729 * n*(n-1)*(n-2)//6 + (p-1)*81*n*(n-1)//2

N=input()
K=int(input())
dig = len(N) - 1

try:
    if K == 2:
        print(solve(int(N[0]),dig,2) + solve(int(N[1]),dig-1,1))
    elif K == 3:
        print(solve(int(N[0]),dig,3) + solve(int(N[1]),dig-1,2) + solve(int(N[2]),dig-2,1))
    elif K == 1:
        print(solve(int(N[0]),dig,1))
except:
    print(0)