strN = input()
N = int(strN)
K = int(input())
ans = 0
if K == 1:
    while(1):
        if N >= 10:
            ans += 9
            N //= 10
        else:
            ans += N
            break
elif K == 2:
    lenN = len(strN)
    if lenN >= 2:
        ans += int(strN[1])
        ans += (int(strN[0]) - 1) * 9
        ans += int(strN[0]) * 9 * (lenN - 2)
        for j in range(1, lenN - 1):
            ans += 9 * 9 * (lenN - j - 1)

        # if lenN >= 3:
        #    ans += (lenN - 2) * 9
        #now_pattern = int(strN[0])
        # for j in range(1, lenN):
        #    ans += now_pattern * (9 ** (lenN - j - 1))
        #    now_pattern *= int(strN[j])

else:
    lenN = len(strN)
    if lenN >= 3:
        ans += int(strN[2])+(lenN-3)*9
        if int(strN[1]) != 0:
            ans += (int(strN[1]) - 1) * 9 * (lenN - 2)
        ans += 9 * 9 * (((lenN - 2) * (lenN - 3)) // 2)
        ans += (int(strN[0]) - 1) * 9 * 9 * (((lenN - 1) * (lenN - 2)) // 2)
        ans += 9*9*9*(((lenN-1)*(lenN-2)*(lenN-3))//6)
        # for h in range(1, lenN - 2):
        #    ans += 9 * 9 * 9*(((lenN-1-h)*(lenN-2-h))//2)
print(ans)
