n = input()
k = int(input())
ans=0
if k == 1 :
    if(len(n)>1):
        for i in range(1,len(n)):
            ans +=9
        print(ans +int(n[0]))
    else:
        print(int(n))

elif k == 2:
    if(len(n) ==1) :
        print(0)
    else:
        for i in range(2,len(n)):
            ans += 9 * (i-1) * 9

        print(ans+int(n[0])*(len(n)-1)*9)

else:
    for i in range(3,len(n)):
        ans += 9*81*(i-1)*(i-2)/2
    print(int(ans+(int(n[0])*81*(len(n)-1)*(len(n)-2)) /2))
    

# n,k= map(int, input().split())
# p = list(map(int,input().split()))

# count = 0
# val = sum(p[0:k])
# val_lis = [val]
# mx_val = val
# index = 0
# mx_index = 0
# for i,j in enumerate(p[k:]):
#     val = val - p[index] + j
#     val_lis.append(val)
#     index +=1
#     if val > mx_val:
#         mx_index = index
#         mx_val = val 
    
# ans = 0
# for i in range(k):
#     ans += ((p[mx_index + i]+1.0)*(p[mx_index+i]))/ (p[mx_index+i] *2.0)
# print(ans)  




# h = sorted(h,reverse = True)
# print(sum(h[k:]))

# s,t= map(str, input().split())
# a,b= map(int, input().split())
# u = input()
# print("x"*len(u))

# if(u == s):
#     print(a-1,b)
# else:
#     print(a,b-1)
