import itertools 
n = int(input())
k = int(input())
digit = len(str(n))
result = 0

# def factorial(p):
#     re = 1
#     for i in range(1, p+1):
#         re *= i
#     return re
# def choose(a, b):
#     return int(factorial(a)/(factorial(b)*factorial(a-b)))
cb = int("9"*k)
# result += choose(cb, k) * choose(5, k)

seq = [1]*(k) + [0]*(digit-k)
realpositionlist = list(set(list(itertools.permutations(seq))))
#最高桁以外
resultnumberlist = []
for l2 in realpositionlist:
    if k == 1:
        for a in range(1,10):
            resultnumberstring = "".join(map(str,l2)).replace("1", str(a), 1) 
            resultnumber =int(resultnumberstring)
            resultnumberlist.append(resultnumber)
    elif k == 2:
        for a in range(1, 10):
            for b in range(1, 10):
                resultnumberstring = "".join(map(str,l2)).replace("1", str(b), 2)
                resultnumberstring = resultnumberstring.replace(str(b), str(a),1)
                resultnumber =int(resultnumberstring)
                resultnumberlist.append(resultnumber)
    elif k == 3:
        for a in range(1, 10):
            for b in range(1, 10):
                for c in range(1, 10):
                    resultnumberstring = "".join(map(str,l2)).replace("1", str(c), 3)
                    resultnumberstring = resultnumberstring.replace(str(c), str(b),2)
                    resultnumberstring = resultnumberstring.replace(str(b), str(a),1)
                    resultnumber =int(resultnumberstring)
                    resultnumberlist.append(resultnumber)

for b in resultnumberlist:
    if b <= n:
        result += 1

print(result)