from math import floor, log10
N = int(input())
K = int(input())
ans = 0
def X(num):
    return floor(log10(num)+1)

def solve_k1(num):
    return 9*(X(num)-1)+int(str(num)[0])

if K == 1:
    print(solve_k1(N))
elif K == 2:
    print(int(0.5*(X(N)-1)*(X(N)-2)*81) + 9*(X(N)-1)*(int(str(N)[0])-1) + solve_k1(int(str(N)[1:])))
else:
    raise TypeError
