from itertools import combinations

n = input()
k = int(input())
ans = 0
li = range(len(n))
if k == 1:
    for x in combinations(li, k):
        if x[0] == len(n)-1:
            ans += int(n[0])
        else:
            ans += 9

elif k == 2:
    for x in combinations(li, k):
        if x[1] != len(n)-1:
            ans += 81
        elif x[1] == len(n)-1 and x[0] == len(n)-2:
            num = int(n[0:2])
            for i in range(1,num+1):
                if '0' not in str(i).zfill(2):
                    ans += 1
        else:
            ans += (int(n[0])) * 9
else:
    for x in combinations(li, k):
        if x[2] != len(n)-1:
            ans += 9**3
        elif x[2] == len(n)-1 and x[1] == len(n)-2 and x[0] == len(n)-3:
            num = int(n[0:3])
            for i in range(1,num+1):
                if '0' not in str(i).zfill(3):
                    ans += 1
        elif x[2] == len(n)-1 and x[1] == len(n)-2:
            num = int(n[0:2])
            for i in range(1, num + 1):
                if '0' not in str(i).zfill(2):
                    ans += 1
        else:
            ans += (int(n[0])) * 9
print(ans)