N = input()
K = int(input())
l = len(N)

if l < K:
    print(0)
    exit()

D3 = [0]*100
n = 0
for i in range(100, 1000):
    if str(i).count("0") == 0:
        n += 1
        D3.append(n)
    else:
        D3.append(n)
D2 = [0]*10
n = 0
for i in range(10, 100):
    if str(i).count("0") == 0:
        n += 1
        D2.append(n)
    else:
        D2.append(n)
ans = 0
if K==3:
    for i in range(l):
        for j in range(i+1, l):
            for k in range(j+1, l):
                if (i,j,k)==(0,1,2):
                    ans += D3[int(N[:3])]
                elif (i,j)==(0,1):
                    ans += 9 * D2[int(N[:2])]
                elif i==0:
                    ans += 81 * int(N[0])
                else:
                    ans += 729
elif K==2:
    for i in range(l):
        for j in range(i+1, l):
            if (i,j)==(0,1):
                ans += D2[int(N[:2])]
            elif i==0:
                ans += 9 * int(N[0])
            else:
                ans += 81
else:
    for i in range(l):
        if i==0:
            ans += int(N[0])
        else:
            ans += 9
print(ans)
