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

import sys

size = len(N)

if K == 1:
    ans = (size - 1) * 9
    first = int(N[0])
    ans += first
elif K == 2:
    ans = 0
    if size == 1:
        ans = 0
    else:
        for i in range(2, size):
            ans += (i - 1) * 81
        first = int(N[0])
        ans += (first - 1) * (size - 1) * 9
        for i in range(1, size):
            nonzero = 0
            if N[i] != "0":
                nonzero = i
                break
        if nonzero == 0:
            print(ans)
            sys.exit()
        ans += int(N[nonzero])
        ans += (size - nonzero - 1) * 9
else:
    if size < 3:
        ans = 0
    else:
        ans = 0
        for i in range(2, size):
            ans += i * (i - 1) // 2 * 81
        for i in range(size):
            ans += (int(N[i]) - 1) * (size - i - 1) * (size - i -2) // 2 * 81

print(ans)