from scipy.misc import comb

N = list(map(int, input()))
K = int(input())

N_len = len(N)

ans = 0
if K == 1:
    ans = N[0] + 9 * (N_len-1)
elif K == 2:
    if N_len >= 2:
        non_zero_index = 0
        index = 1
        while index < N_len:
            if N[index] != 0:
                non_zero_index = index
                break
            index += 1
        ans = N[non_zero_index] + 9 * len(N[non_zero_index+1:]) 
        #print(f'ans {ans}')
        # 1~N[0]-1
        ans += (N[0]-1) * 9 *(N_len-1)
        #print(f'ans {ans}')
        for i in range(1,N_len-1):
            ans += 9*9*i
elif K == 3:
    if N_len >= 3:
        non_zero_index = [0] * 2
        index = 1
        count = 0
        while count < 2 and index < N_len:
            if N[index] != 0:
                non_zero_index[count] = index
                count += 1
            index += 1
        # N[0],N[1]　を固定
        #print(f'index {index}')
        if index <= N_len-2:
            ans = N[non_zero_index[1]] + 9 * len(N[non_zero_index[1]+1:]) 
        #print(f'ans {ans}')
        # N[0], 1~N[1]-1
        ans += max(N[non_zero_index[0]]-1,0) * 9 * len(N[non_zero_index[0]+1:])
        #print(f'ans {ans}')
        ans += 9**2 * comb(len(N[non_zero_index[1]:]),2,exact=True)
        # 1~N[0]-1
        ans += (N[0]-1) * 9**2 * comb(N_len-1,2,exact=True)     
        #print(f'ans {ans}')
        # N[0] = 0
        for i in range(2,N_len-1):
            ans += 9**3 * comb(i,2,exact=True)


#print(9**3*comb(N_len,3,exact=True))
print(ans)
#print(f'diff {9**3*comb(N_len,3,exact=True)-ans}')