import math

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

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

N_length = len(N)

fi_ans = 0

def one(N_str):
    ans = 0
    length = len(N_str)
    ans += (length-1)*9
    top = int(N_str[0])
    ans += top
    return ans

def two(N_str):
    length = len(N_str)
    ans = 0
    if length == 1:
        ans = 0
    elif length == 2:
        ans += (int(N_str[0])-1)*9
        ans += int(N_str[1])
    else:
        ans += comb(length-1, K) * 9 * 9
        top = int(N_str[0])
        first_n_0 = -1
        for i in range(length-1):
            if int(N_str[i+1]) != 0:
                first_n_0 = i+1
                break
        if 0 < first_n_0:
            ans += (top-1)*(length-1)*9
            ans += one(N_str[first_n_0:])
    return ans

if K == 1:
    fi_ans = one(N)
elif K == 2:
    fi_ans = two(N)
else:
    if N_length < 3:
        fi_ans = 0
    elif N_length == 3:
        fi_ans += (int(N[0])-1) * 9 * 9
        top = int(N[0])
        sec = int(N[1])
        thr = int(N[2])
        if sec != 0:
            fi_ans += (sec - 1) * 9
            fi_ans += thr
    else:
        fi_ans += comb(N_length-1, K) * 9 * 9 * 9
        top = int(N[0])
        first_n_0 = -1
        second_n_0 = -1
        for i in range(N_length-1):
            if int(N[i+1]) != 0:
                if first_n_0 < 0:
                    first_n_0 = i+1
                else:
                    second_n_0 = i+1
                    break
        if 0 < first_n_0 < N_length-1:
            fi_ans += (top-1)*comb(N_length-1, K-1)*9*9
            fi_ans += two(N[first_n_0:])

print(fi_ans)
