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

nn = str(n)
le = len(nn)
ans1 = 0
if le > k:
    ans1 = 1
    for i in range(k):
        ans1 = 9*ans1*(le-i-1)/(i+1)

ans2 = 0
if k==1:
    ans2 = int(nn[0])
elif k==2:
    ans2 += 9*(int(nn[0])-1)*(le-1)
    for i  in range(le-1):
        if int(nn[i+1])>0:
            ans2 += int(nn[i+1])+9*(le-i-2)
            break
elif k==3:
    ans2 += 81*(int(nn[0])-1)*(le-1)*(le-2)/2
    for i  in range(le-1):
        if int(nn[i+1])>0:
            ans2 += 9*(int(nn[i+1])-1)*(le-i-2)
            for j in range(i+2,le):
                if  int(nn[j])>0:
                    ans2 += int(nn[j])+9*(le-j-1)
                    break
if le >= k:
    print(int(ans1+ans2))
else:
    print(0)
