n=int(eval(input()))

K=int(eval(input()))

if K==1:

    counter=0

    for i in range(100):

        for j in range(1,10):

            a="0"*(i)+str(j)+"0"*(99-i)

            if 1<=int(a)<=n:

                counter+=1

    print(counter)

elif K==2:

    counter=0

    for i in range(100):

        for j in range(i+1,100):

            for k in range(1,10):

                for l in range(1,10):

                    a="0"*(i)+str(k)+"0"*(j-i-1)+str(l)+"0"*(99-j)

                    if 1<=int(a)<=n:

                        counter+=1

    print(counter)

elif K==3:

    counter=0

    for i in range(100):

        if 100-i>len(str(n)):

            pass

        elif 100-i<len(str(n)):

            for j in range(i+1,100):

                for k in range(j+1,100):

                    counter+=9*9*9

        elif 100-i==len(str(n)):

            for j in range(i+1,100):

                for k in range(j+1,100):



                        for b in range(1,10):

                            for c in range(1,10):

                                P=(str(n)[0])+"0"*(j-i-1)+str(b)+"0"*(k-j-1)+str(c)+"0"*(99-k)

                                if 1<=int(P)<=n:

                                    counter+=1

            counter+=((98-i)*(99-i)//2)*9*9*(int(str(n)[0])-1)

    print(counter)

                    





                    

#almost everywhere zero



n=eval(input())

k=int(eval(input()))

dp_small=[[0 for i in range(4)] for j in range(101)]

dp_same=[[0 for i in range(4)] for j in range(101)]



#dp/smallすでに小さい

#dp_largeまだ小さいかどうかわからない

for i in range(101):

    dp_small[i][0]=1

dp_small[0][0]=0

dp_same[0][0]=1

for i in range(len(n)):

    a=int(n[i])

    #左からi+1番目の桁について考える

    if a!=0:

        dp_small[i+1][1]=dp_small[i][1]+9*dp_small[i][0]+(a-1)*dp_same[i][0]+dp_same[i][1]

        dp_small[i+1][2]=dp_small[i][2]+9*dp_small[i][1]+(a-1)*dp_same[i][1]+dp_same[i][2]

        dp_small[i+1][3]=dp_small[i][3]+9*dp_small[i][2]+(a-1)*dp_same[i][2]+dp_same[i][3]



        dp_same[i+1][1]=dp_same[i][0]

        dp_same[i+1][2]=dp_same[i][1]

        dp_same[i+1][3]=dp_same[i][2]       

        

        

        

        

    elif a==0:

        dp_small[i+1][1]=dp_small[i][1]+9*dp_small[i][0]

        dp_small[i+1][2]=dp_small[i][2]+9*dp_small[i][1]

        dp_small[i+1][3]=dp_small[i][3]+9*dp_small[i][2]



        dp_same[i+1][1]=dp_same[i][1]

        dp_same[i+1][2]=dp_same[i][2]

        dp_same[i+1][3]=dp_same[i][3]

        

L=len(n)

sums= dp_small[L][k]+dp_same[L][k]



print(sums)

n = int(eval(input()))
K = int(eval(input()))
if K == 1:
    counter = 0
    for i in range(100):
        for j in range(1, 10):
            a = "0" * (i) + str(j) + "0" * (99 - i)
            if 1 <= int(a) <= n:
                counter += 1
    print(counter)
elif K == 2:
    counter = 0
    for i in range(100):
        for j in range(i + 1, 100):
            for k in range(1, 10):
                for l in range(1, 10):
                    a = "0" * (i) + str(k) + "0" * (j - i - 1) + str(l) + "0" * (99 - j)
                    if 1 <= int(a) <= n:
                        counter += 1
    print(counter)
elif K == 3:
    counter = 0
    for i in range(100):
        if 100 - i > len(str(n)):
            pass
        elif 100 - i < len(str(n)):
            for j in range(i + 1, 100):
                for k in range(j + 1, 100):
                    counter += 9 * 9 * 9
        elif 100 - i == len(str(n)):
            for j in range(i + 1, 100):
                for k in range(j + 1, 100):
                    for b in range(1, 10):
                        for c in range(1, 10):
                            P = (
                                (str(n)[0])
                                + "0" * (j - i - 1)
                                + str(b)
                                + "0" * (k - j - 1)
                                + str(c)
                                + "0" * (99 - k)
                            )
                            if 1 <= int(P) <= n:
                                counter += 1
            counter += ((98 - i) * (99 - i) // 2) * 9 * 9 * (int(str(n)[0]) - 1)
    print(counter)

# almost everywhere zero
n = eval(input())
k = int(eval(input()))
dp_small = [[0 for i in range(4)] for j in range(101)]
dp_same = [[0 for i in range(4)] for j in range(101)]
# dp/smallすでに小さい
# dp_largeまだ小さいかどうかわからない
for i in range(101):
    dp_small[i][0] = 1
dp_small[0][0] = 0
dp_same[0][0] = 1
for i in range(len(n)):
    a = int(n[i])
    # 左からi+1番目の桁について考える
    if a != 0:
        dp_small[i + 1][1] = (
            dp_small[i][1]
            + 9 * dp_small[i][0]
            + (a - 1) * dp_same[i][0]
            + dp_same[i][1]
        )
        dp_small[i + 1][2] = (
            dp_small[i][2]
            + 9 * dp_small[i][1]
            + (a - 1) * dp_same[i][1]
            + dp_same[i][2]
        )
        dp_small[i + 1][3] = (
            dp_small[i][3]
            + 9 * dp_small[i][2]
            + (a - 1) * dp_same[i][2]
            + dp_same[i][3]
        )
        dp_same[i + 1][1] = dp_same[i][0]
        dp_same[i + 1][2] = dp_same[i][1]
        dp_same[i + 1][3] = dp_same[i][2]
    elif a == 0:
        dp_small[i + 1][1] = dp_small[i][1] + 9 * dp_small[i][0]
        dp_small[i + 1][2] = dp_small[i][2] + 9 * dp_small[i][1]
        dp_small[i + 1][3] = dp_small[i][3] + 9 * dp_small[i][2]
        dp_same[i + 1][1] = dp_same[i][1]
        dp_same[i + 1][2] = dp_same[i][2]
        dp_same[i + 1][3] = dp_same[i][3]
L = len(n)
sums = dp_small[L][k] + dp_same[L][k]
print(sums)

-n = int(eval(input())) -K = int(eval(input())) -if K == 1: -    counter = 0 -    for i in range(100): -        for j in range(1, 10): -            a = "0" * (i) + str(j) + "0" * (99 - i) -            if 1 <= int(a) <= n: -                counter += 1 -    print(counter) -elif K == 2: -    counter = 0 -    for i in range(100): -        for j in range(i + 1, 100): -            for k in range(1, 10): -                for l in range(1, 10): -                    a = "0" * (i) + str(k) + "0" * (j - i - 1) + str(l) + "0" * (99 - j) -                    if 1 <= int(a) <= n: -                        counter += 1 -    print(counter) -elif K == 3: -    counter = 0 -    for i in range(100): -        if 100 - i > len(str(n)): -            pass -        elif 100 - i < len(str(n)): -            for j in range(i + 1, 100): -                for k in range(j + 1, 100): -                    counter += 9 * 9 * 9 -        elif 100 - i == len(str(n)): -            for j in range(i + 1, 100): -                for k in range(j + 1, 100): -                    for b in range(1, 10): -                        for c in range(1, 10): -                            P = ( -                                (str(n)[0]) -                                + "0" * (j - i - 1) -                                + str(b) -                                + "0" * (k - j - 1) -                                + str(c) -                                + "0" * (99 - k) -                            ) -                            if 1 <= int(P) <= n: -                                counter += 1 -            counter += ((98 - i) * (99 - i) // 2) * 9 * 9 * (int(str(n)[0]) - 1) -    print(counter) +# almost everywhere zero +n = eval(input()) +k = int(eval(input())) +dp_small = [[0 for i in range(4)] for j in range(101)] +dp_same = [[0 for i in range(4)] for j in range(101)] +# dp/smallすでに小さい +# dp_largeまだ小さいかどうかわからない +for i in range(101): +    dp_small[i][0] = 1 +dp_small[0][0] = 0 +dp_same[0][0] = 1 +for i in range(len(n)): +    a = int(n[i]) +    # 左からi+1番目の桁について考える +    if a != 0: +        dp_small[i + 1][1] = ( +            dp_small[i][1] +            + 9 * dp_small[i][0] +            + (a - 1) * dp_same[i][0] +            + dp_same[i][1] +        ) +        dp_small[i + 1][2] = ( +            dp_small[i][2] +            + 9 * dp_small[i][1] +            + (a - 1) * dp_same[i][1] +            + dp_same[i][2] +        ) +        dp_small[i + 1][3] = ( +            dp_small[i][3] +            + 9 * dp_small[i][2] +            + (a - 1) * dp_same[i][2] +            + dp_same[i][3] +        ) +        dp_same[i + 1][1] = dp_same[i][0] +        dp_same[i + 1][2] = dp_same[i][1] +        dp_same[i + 1][3] = dp_same[i][2] +    elif a == 0: +        dp_small[i + 1][1] = dp_small[i][1] + 9 * dp_small[i][0] +        dp_small[i + 1][2] = dp_small[i][2] + 9 * dp_small[i][1] +        dp_small[i + 1][3] = dp_small[i][3] + 9 * dp_small[i][2] +        dp_same[i + 1][1] = dp_same[i][1] +        dp_same[i + 1][2] = dp_same[i][2] +        dp_same[i + 1][3] = dp_same[i][3] +L = len(n) +sums = dp_small[L][k] + dp_same[L][k] +print(sums)