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])

def mitukeru_not_zero(num):
    for i in range(len(str(num))):
        if i != 0 and str(num)[i] != "0":
            return i
    else:
        return -1 

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