n = input()
k = int(input())
n_len = len(str(n))

x = [1]*(n_len)
for i in range(n_len-1):
    x[i+1] = x[i]*(i+1)

def calc(i,j):
    return x[i]/x[j]/x[i-j]

m = 0
i = 0
m_ind = []
while i < n_len:
    if int(n[i]) != 0:
        m_ind += [i]
        m += 1
    if m == k:
        break
    i += 1

if n_len < k:
    print(0)
    
elif n_len == k:
    if k == 3:
        if m == 2 and m_ind[1] == 1:
            count = 0
        else:
            count = (int(n[0])-1)*9**2 + (max(1,int(n[1]))-1)*9 + int(n[2])
    if k == 2:
        count = (int(n[0])-1)*9 + int(n[1])
    if k == 1:
        count = int(n)
    print(count)
    
else:
    count = 0
    count += calc(n_len-1,k)*9**k
    if k == 1:
        count += int(n[0])
     
    else:
        count += calc(n_len-1,k-1)*9**(k-1)*(int(n[0])-1)
        if k == 2:
            if m == 2:
                count += calc(n_len-m_ind[1]-1,k-1)*9**(k-1)
                count += int(n[m_ind[1]])
            
        if k == 3:
            if m == 2:
                count += calc(n_len-m_ind[1]-1,k-1)*9**(k-1)
                count += calc(n_len-m_ind[1]-1,k-2)*9**(k-2)*(int(n[m_ind[1]])-1)
            elif m == 3:
                count += calc(n_len-m_ind[1]-1,k-1)*9**(k-1)
                count += calc(n_len-m_ind[1]-1,k-2)*9**(k-2)*(int(n[m_ind[1]])-1)
                count += calc(n_len-m_ind[2]-1,k-2)*9**(k-2)
                count += int(n[m_ind[2]])
            
    print(int(count))