n=int(input())
k=int(input())

p=0
while 10**(p+1)<=n:
    p+=1 #10**p<=n<10**(p+1)

m=0
l=[]
if k==1:
    if p==0:
        m=n
    else:
        m=9
        for i in range(1,p):
            m+=9
        for i in range(9):
            if (i+1)*(10**p)<=n:
                m+=1
    
elif k==2:
    if p==0:
        m=0
    elif p==1:
        m=n-9-n//10
    else:
        for i in range(1,p):
            m+=i*9*9
        for i in range(p):
            for j in range(1,10):
                for q in range(1,10):
                    if j*(10**p)+q*(10**i)<=n:
                        m+=1
    
elif k==3:
    if p==0:
        m=0
    elif p==1:
        m=0
    else:
        for i in range(2,p):
            m+=i*(i-1)*9*9*9//2
        for i in range(1,p):
            for s in range(i):
                for j in range(1,10):
                    for q in range(1,10):
                        for r in range(1,10):
                            if j*(10**p)+q*(10**i)+r*(10**s)<=n:
                                m+=1
print(m)
