n=int(eval(input()))

k=int(eval(input()))

s=len(list(str(n)))

if k==1:

    ans=(s-1)*9

    for i in range(9):

        if n>=(10**(s-1))*(i+1):

            ans+=1

elif k==2:

    ans=9*9*(s-1)*(s-2)//2

    for i in range(9):

        for j in range(s-1):

            for p in range(9):

                if n>=(10**(s-1))*(i+1)+(10**j)*(p+1):

                    ans+=1

else:

    ans=9*81*(s-1)*(s-2)*(s-3)//6

    f=int(list(str(n))[0])

    ans+=(f-1)*81*(s-1)*(s-2)//2

    for p in range(s-1):

        for q in range(s-1):

            if p<q:

                for t in range(1,10):

                    for u in range(1,10):

                        if n>=(10**(s-1))*f+(10**p)*t+(10**q)*u:

                            ans+=1

print(ans)

n = int(eval(input()))

N = len(str(n))

k = int(eval(input()))

s = [int(i) for i in str(n)]

dpi = [[0]*(k+1) for _ in range(N+1)]

dpj = [[0]*(k+1) for _ in range(N+1)]

dpi[0][0] = 1

for i in range(N):

    for j in range(k+1):

        dpi[i+1][j] += dpi[i][j]*(s[i]==0)

        dpj[i+1][j] += dpj[i][j]+dpi[i][j]*(s[i]>0)

        if j < k:

            dpi[i+1][j+1]+=dpi[i][j]*(s[i]>0)

            dpj[i+1][j+1]+=dpj[i][j]*9+dpi[i][j]*max(0,s[i]-1)

print((dpi[N][k]+dpj[N][k]))

n = int(eval(input()))
k = int(eval(input()))
s = len(list(str(n)))
if k == 1:
    ans = (s - 1) * 9
    for i in range(9):
        if n >= (10 ** (s - 1)) * (i + 1):
            ans += 1
elif k == 2:
    ans = 9 * 9 * (s - 1) * (s - 2) // 2
    for i in range(9):
        for j in range(s - 1):
            for p in range(9):
                if n >= (10 ** (s - 1)) * (i + 1) + (10**j) * (p + 1):
                    ans += 1
else:
    ans = 9 * 81 * (s - 1) * (s - 2) * (s - 3) // 6
    f = int(list(str(n))[0])
    ans += (f - 1) * 81 * (s - 1) * (s - 2) // 2
    for p in range(s - 1):
        for q in range(s - 1):
            if p < q:
                for t in range(1, 10):
                    for u in range(1, 10):
                        if n >= (10 ** (s - 1)) * f + (10**p) * t + (10**q) * u:
                            ans += 1
print(ans)

n = int(eval(input()))
N = len(str(n))
k = int(eval(input()))
s = [int(i) for i in str(n)]
dpi = [[0] * (k + 1) for _ in range(N + 1)]
dpj = [[0] * (k + 1) for _ in range(N + 1)]
dpi[0][0] = 1
for i in range(N):
    for j in range(k + 1):
        dpi[i + 1][j] += dpi[i][j] * (s[i] == 0)
        dpj[i + 1][j] += dpj[i][j] + dpi[i][j] * (s[i] > 0)
        if j < k:
            dpi[i + 1][j + 1] += dpi[i][j] * (s[i] > 0)
            dpj[i + 1][j + 1] += dpj[i][j] * 9 + dpi[i][j] * max(0, s[i] - 1)
print((dpi[N][k] + dpj[N][k]))

+N = len(str(n)) -s = len(list(str(n))) -if k == 1: -    ans = (s - 1) * 9 -    for i in range(9): -        if n >= (10 ** (s - 1)) * (i + 1): -            ans += 1 -elif k == 2: -    ans = 9 * 9 * (s - 1) * (s - 2) // 2 -    for i in range(9): -        for j in range(s - 1): -            for p in range(9): -                if n >= (10 ** (s - 1)) * (i + 1) + (10**j) * (p + 1): -                    ans += 1 -else: -    ans = 9 * 81 * (s - 1) * (s - 2) * (s - 3) // 6 -    f = int(list(str(n))[0]) -    ans += (f - 1) * 81 * (s - 1) * (s - 2) // 2 -    for p in range(s - 1): -        for q in range(s - 1): -            if p < q: -                for t in range(1, 10): -                    for u in range(1, 10): -                        if n >= (10 ** (s - 1)) * f + (10**p) * t + (10**q) * u: -                            ans += 1 -print(ans) +s = [int(i) for i in str(n)] +dpi = [[0] * (k + 1) for _ in range(N + 1)] +dpj = [[0] * (k + 1) for _ in range(N + 1)] +dpi[0][0] = 1 +for i in range(N): +    for j in range(k + 1): +        dpi[i + 1][j] += dpi[i][j] * (s[i] == 0) +        dpj[i + 1][j] += dpj[i][j] + dpi[i][j] * (s[i] > 0) +        if j < k: +            dpi[i + 1][j + 1] += dpi[i][j] * (s[i] > 0) +            dpj[i + 1][j + 1] += dpj[i][j] * 9 + dpi[i][j] * max(0, s[i] - 1) +print((dpi[N][k] + dpj[N][k]))