N = int(input())
K = int(input())
NStr = str(N)

def one(string):
    L = len(string)
    ans = (L-1)*9
    ans += int(string[0])
    return ans

def two(string):
    ans = sum(range(L - 1)) * 81
    head = int(string[0])
    ans += (head - 1) * 9 * (L - 1)
    ans += one(string[1:])
    return ans

ans = 0
L = len(str(N))
if K == 1:
    ans = one(NStr)
elif K == 2:
    ans = two(NStr)
else:
    seed = [0]*(L-1)
    for i in range(1, L-1):
        seed[i] = seed[i-1] + i
    ans = sum(seed[:L-2]) * 81 *9
    head = int(NStr[0])
    ans += (head-1)*81*(seed[L-2])
    ans += two(NStr[1:])

print(ans)