from scipy.special import comb

def k_1(n):
    h = int(n[0])
    res = 0
    res += max((h-1), 1) * (len(n)-1) * 9
    res += h
    return res

def k_2(n):
    h = int(n[0])
    res = 0
    res += comb(len(n)-1, 2) * 9 * 9
    res += (h-1) * (len(n)-1) * 9
    res += k_1(n[1:])
    return res

def k_3(n):
    h = int(n[0])
    res = 0
    res += comb(len(n)-1, 3) * 9 * 9 * 9
    res += (h-1) * comb(len(n)-1, 2) * 9 * 9
    res += k_2(n[1:])
    return res

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

res = 0

if K == 1:
    res = k_1(N)
elif K == 2:
    res = k_2(N)
else:
    res = k_3(N)

print(int(res))
