import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
K = int(input())

if K ==1:
    ans = 0
    l = len(str(N))
    ans += 9*(l-1)
    head = int(str(N)[0])
    ans += head
    print(ans)
elif K == 2:
    ans = 0
    l = len(str(N))
    for i in range(1,l-1):
        ans += 9*(9*i)
    
    head = int(str(N)[0])
    ans += (head-1)*(9*(l-1))
    ans += int(str(N)[1]) + (9*(l-2))
    print(ans)
elif K == 3:
    ans = 0
    l = len(str(N))
    for i in range(0,l-3):
        ans += 9*(81*combinations_count(i+2,2))
    
    head = int(str(N)[0])
    ans += (head-1)*(81*combinations_count(l-1,2))
    ans += ( (int(str(N)[1])-1) * 9  * (l-2) )  + int(str(N)[2]) + (9 * (l-3) ) 
    if l > 3 : 
        ans += (81*combinations_count(l-2,2))
    print(ans)