## ABC154E

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

n = input()
k = input()
k = int(k)
l = len(n)
n = list(map(int, n))
ans = 0
if k==1:
    ans = n[0] + 9 * (l-1)
elif k==2:
    if l>=2:
        ans = (n[1] + (n[0]-1)*9) + n[0]*(l-2)*9 + (l-1)*(l-2)//2 * 81
    else:
        ans = 0
else:
    for i in range(l):
        for j in range(i+1,l):
            for kk in range(j+1,l):
                num = len(set([i,j,kk]))
                if i==0:
                    if num==1:
                        ans += n[0]
                    elif num==2:
                        if kk==1:
                            ans += n[0] * n[1]
                        else:
                            ans += n[0] * 9
                    elif k>=3:
                        if j==1:
                            if kk==2:
                                ans += n[0] * n[1] * n[2]
                            else:
                                ans += n[0] * n[1] * 9
                        else:
                            ans += n[0] * 81
                else:
                    if i==j==kk:
                        ans += 9
                    elif i==j and k>=2:
                        ans += 81
                    elif j==kk and k>=2:
                        ans += 81
                    elif k>=3:
                        ans += 81*9
print(ans)
