import functools
import sys


@functools.lru_cache(None)
def doit(n, k):
    if len(n) == 0 or k < 0:
        return k == 0
    d = int(n[0])
    return sum(doit(n[1:] if i == d else '9' * (len(n) - 1), k - 1 if i > 0 else k) for i in range(d + 1))


sys.setrecursionlimit(404)
print(doit(input(), int(input()))) import functools functools import sys sys def doit(n, k):
    if len(n) == 0 or k < 0:
        return k == 0
    d = int(n[0])
    return sum(doit(n[1:] if i == d else '9' * (len(n) - 1), k - 1 if i > 0 else k) for i in range(d + 1)) doit if len(n) == 0 or k < 0:
        return k == 0
     len(n) == 0 or k < 0 len(n) == 0 len(n) len n 0 k < 0 k 0 return k == 0 k == 0 k 0 d = int(n[0]) d int(n[0]) int n[0] n 0 return sum(doit(n[1:] if i == d else '9' * (len(n) - 1), k - 1 if i > 0 else k) for i in range(d + 1)) sum(doit(n[1:] if i == d else '9' * (len(n) - 1), k - 1 if i > 0 else k) for i in range(d + 1)) sum doit(n[1:] if i == d else '9' * (len(n) - 1), k - 1 if i > 0 else k) doit n[1:] if i == d else '9' * (len(n) - 1) i == d i d n[1:] n 1: 1 '9' * (len(n) - 1) '9' len(n) - 1 len(n) len n 1 k - 1 if i > 0 else k i > 0 i 0 k - 1 k 1 k n n k k @functools.lru_cache(None) doit None @functools.lru_cache(None) functools.lru_cache None doit sys.setrecursionlimit(404) sys.setrecursionlimit sys setrecursionlimit 404 print(doit(input(), int(input()))) print doit(input(), int(input())) doit input() input int(input()) int input() input def doit(n, k):
    if len(n) == 0 or k < 0:
        return k == 0
    d = int(n[0])
    return sum(doit(n[1:] if i == d else '9' * (len(n) - 1), k - 1 if i > 0 else k) for i in range(d + 1)) def doit(n, k):
    if len(n) == 0 or k < 0:
        return k == 0
    d = int(n[0])
    return sum(doit(n[1:] if i == d else '9' * (len(n) - 1), k - 1 if i > 0 else k) for i in range(d + 1)) doit
import functools
import sys


@functools.lru_cache(None)
def doit(n, k):
    if len(n) == 0 or k < 0:
        return k == 0
    d = int(n[0])
    return sum(doit(n[1:] if i == d else '9' * (len(n) - 1), k - 1 if i > 0 else k) for i in range(d + 1))


sys.setrecursionlimit(404)
print(doit(input(), int(input())))
