import math
import itertools
n=int(input())
k=int(input())
def comb(n,k):
    return len(list(itertools.combinations(range(n), k)))
x=str(n)
m=len(x)
ans=0
for i in range(1,m):
    ans+=(comb(i-1,k-1)*(9**k))
if k==1:
    for i in range(1,10):
        if i*(10**(m-1))<=n:
            ans+=1
elif k==2:
    for i in range(1,10):
        if i*(10**(m-1))<=n:
            for j in range(m-1):
                for a in range(1,10):
                    if i*(10**(m-1))+a*(10**(j))<=n:
                        ans+=1
                    else:
                        break
        else:
            break
else:
    po=[10**i for i in range(m)]
    for i in range(1,10):
        if i*po[m-1]<=n:
            for j in range(m-1):
                for a in range(1,10):
                    if i*po[m-1]+a*po[j]<=n:
                        for b in range(j):
                            for c in range(1,10):
                                ans+=(i*po[m-1]+a*po[j]+c*po[b]<=n)
                    else:
                        break
        else:
            break
print(ans) import math math import itertools itertools n=int(input()) n int(input()) int input() input k=int(input()) k int(input()) int input() input def comb(n,k):
    return len(list(itertools.combinations(range(n), k))) comb return len(list(itertools.combinations(range(n), k))) len(list(itertools.combinations(range(n), k))) len list(itertools.combinations(range(n), k)) list itertools.combinations(range(n), k) itertools.combinations itertools combinations range(n) range n k n n k k x=str(n) x str(n) str n m=len(x) m len(x) len x ans=0 ans 0 for i in range(1,m):
    ans+=(comb(i-1,k-1)*(9**k)) i range(1,m) range 1 m ans+=(comb(i-1,k-1)*(9**k)) ans comb(i-1,k-1)*(9**k) comb(i-1,k-1) comb i-1 i 1 k-1 k 1 9**k 9 k if k==1:
    for i in range(1,10):
        if i*(10**(m-1))<=n:
            ans+=1
elif k==2:
    for i in range(1,10):
        if i*(10**(m-1))<=n:
            for j in range(m-1):
                for a in range(1,10):
                    if i*(10**(m-1))+a*(10**(j))<=n:
                        ans+=1
                    else:
                        break
        else:
            break
else:
    po=[10**i for i in range(m)]
    for i in range(1,10):
        if i*po[m-1]<=n:
            for j in range(m-1):
                for a in range(1,10):
                    if i*po[m-1]+a*po[j]<=n:
                        for b in range(j):
                            for c in range(1,10):
                                ans+=(i*po[m-1]+a*po[j]+c*po[b]<=n)
                    else:
                        break
        else:
            break k==1 k 1 for i in range(1,10):
        if i*(10**(m-1))<=n:
            ans+=1 i range(1,10) range 1 10 if i*(10**(m-1))<=n:
            ans+=1 i*(10**(m-1))<=n i*(10**(m-1)) i 10**(m-1) 10 m-1 m 1 n ans+=1 ans 1 elif k==2:
    for i in range(1,10):
        if i*(10**(m-1))<=n:
            for j in range(m-1):
                for a in range(1,10):
                    if i*(10**(m-1))+a*(10**(j))<=n:
                        ans+=1
                    else:
                        break
        else:
            break k==2 k 2 for i in range(1,10):
        if i*(10**(m-1))<=n:
            for j in range(m-1):
                for a in range(1,10):
                    if i*(10**(m-1))+a*(10**(j))<=n:
                        ans+=1
                    else:
                        break
        else:
            break i range(1,10) range 1 10 if i*(10**(m-1))<=n:
            for j in range(m-1):
                for a in range(1,10):
                    if i*(10**(m-1))+a*(10**(j))<=n:
                        ans+=1
                    else:
                        break
        else:
            break i*(10**(m-1))<=n i*(10**(m-1)) i 10**(m-1) 10 m-1 m 1 n for j in range(m-1):
                for a in range(1,10):
                    if i*(10**(m-1))+a*(10**(j))<=n:
                        ans+=1
                    else:
                        break
         j range(m-1) range m-1 m 1 for a in range(1,10):
                    if i*(10**(m-1))+a*(10**(j))<=n:
                        ans+=1
                    else:
                        break
         a range(1,10) range 1 10 if i*(10**(m-1))+a*(10**(j))<=n:
                        ans+=1
                    else:
                        break
         i*(10**(m-1))+a*(10**(j))<=n i*(10**(m-1))+a*(10**(j)) i*(10**(m-1)) i 10**(m-1) 10 m-1 m 1 a*(10**(j)) a 10**(j) 10 j n ans+=1 ans 1 break break 10**i for i in range(m) for i in range(m) i range(m) range m for i in range(m) 10**i 10 i po=[10**i for i in range(m)] po [10**i for i in range(m)] for i in range(1,10):
        if i*po[m-1]<=n:
            for j in range(m-1):
                for a in range(1,10):
                    if i*po[m-1]+a*po[j]<=n:
                        for b in range(j):
                            for c in range(1,10):
                                ans+=(i*po[m-1]+a*po[j]+c*po[b]<=n)
                    else:
                        break
        else:
            break i range(1,10) range 1 10 if i*po[m-1]<=n:
            for j in range(m-1):
                for a in range(1,10):
                    if i*po[m-1]+a*po[j]<=n:
                        for b in range(j):
                            for c in range(1,10):
                                ans+=(i*po[m-1]+a*po[j]+c*po[b]<=n)
                    else:
                        break
        else:
            break i*po[m-1]<=n i*po[m-1] i po[m-1] po m-1 m 1 n for j in range(m-1):
                for a in range(1,10):
                    if i*po[m-1]+a*po[j]<=n:
                        for b in range(j):
                            for c in range(1,10):
                                ans+=(i*po[m-1]+a*po[j]+c*po[b]<=n)
                    else:
                        break
         j range(m-1) range m-1 m 1 for a in range(1,10):
                    if i*po[m-1]+a*po[j]<=n:
                        for b in range(j):
                            for c in range(1,10):
                                ans+=(i*po[m-1]+a*po[j]+c*po[b]<=n)
                    else:
                        break
         a range(1,10) range 1 10 if i*po[m-1]+a*po[j]<=n:
                        for b in range(j):
                            for c in range(1,10):
                                ans+=(i*po[m-1]+a*po[j]+c*po[b]<=n)
                    else:
                        break
         i*po[m-1]+a*po[j]<=n i*po[m-1]+a*po[j] i*po[m-1] i po[m-1] po m-1 m 1 a*po[j] a po[j] po j n for b in range(j):
                            for c in range(1,10):
                                ans+=(i*po[m-1]+a*po[j]+c*po[b]<=n)
                     b range(j) range j for c in range(1,10):
                                ans+=(i*po[m-1]+a*po[j]+c*po[b]<=n)
                     c range(1,10) range 1 10 ans+=(i*po[m-1]+a*po[j]+c*po[b]<=n) ans i*po[m-1]+a*po[j]+c*po[b]<=n i*po[m-1]+a*po[j]+c*po[b] i*po[m-1]+a*po[j] i*po[m-1] i po[m-1] po m-1 m 1 a*po[j] a po[j] po j c*po[b] c po[b] po b n break break print(ans) print ans ans+=1 1 ans n=int(input()) int(input()) n k=int(input()) int(input()) k def comb(n,k):
    return len(list(itertools.combinations(range(n), k))) def comb(n,k):
    return len(list(itertools.combinations(range(n), k))) comb m=len(x) len(x) m ans=0 0 ans x=str(n) str(n) x po=[10**i for i in range(m)] [10**i for i in range(m)] po ans+=1 1 ans ans+=(comb(i-1,k-1)*(9**k)) comb(i-1,k-1)*(9**k) ans ans+=(i*po[m-1]+a*po[j]+c*po[b]<=n) i*po[m-1]+a*po[j]+c*po[b]<=n ans
import math
import itertools
n=int(input())
k=int(input())
def comb(n,k):
    return len(list(itertools.combinations(range(n), k)))
x=str(n)
m=len(x)
ans=0
for i in range(1,m):
    ans+=(comb(i-1,k-1)*(9**k))
if k==1:
    for i in range(1,10):
        if i*(10**(m-1))<=n:
            ans+=1
elif k==2:
    for i in range(1,10):
        if i*(10**(m-1))<=n:
            for j in range(m-1):
                for a in range(1,10):
                    if i*(10**(m-1))+a*(10**(j))<=n:
                        ans+=1
                    else:
                        break
        else:
            break
else:
    po=[10**i for i in range(m)]
    for i in range(1,10):
        if i*po[m-1]<=n:
            for j in range(m-1):
                for a in range(1,10):
                    if i*po[m-1]+a*po[j]<=n:
                        for b in range(j):
                            for c in range(1,10):
                                ans+=(i*po[m-1]+a*po[j]+c*po[b]<=n)
                    else:
                        break
        else:
            break
print(ans)
