from scipy.misc import comb

def solve_one(N):
    N_len = len(N)
    ans = N[0] + 9 * (N_len-1)
    return ans

def solve_two(N):
    N_len = len(N)
    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
    return ans

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

N_len = len(N)

ans = 0
if K == 1:
    ans = solve_one(N)
elif K == 2:
    if N_len >= 2:
        ans = solve_two(N)
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]　を固定
        if non_zero_index[1] < N_len:
            ans = N[non_zero_index[1]] + 9 * len(N[non_zero_index[1]+1:]) 
        # N[0], 1~N[1]-1
        ans += max(N[non_zero_index[0]]-1,0) * 9 * len(N[non_zero_index[0]+1:])
        # N[0], N[1] == 0
        ans += solve_two(N[non_zero_index[1]:])
        # 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(ans)