import sys
sys.setrecursionlimit(303)


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


print(doit(input(), int(input()), {})) import sys sys sys.setrecursionlimit(303) sys.setrecursionlimit sys setrecursionlimit 303 def doit(n, k, m):
    if len(n) == 0 or k < 0:
        return k == 0
    if (n, k) not in m:
        d = int(n[0])
        m[(n, k)] = sum(doit(n[1:] if i == d else '9' * (len(n) - 1), k - 1 if i > 0 else k, m) for i in range(d + 1))
    return m[(n, k)] 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 if (n, k) not in m:
        d = int(n[0])
        m[(n, k)] = sum(doit(n[1:] if i == d else '9' * (len(n) - 1), k - 1 if i > 0 else k, m) for i in range(d + 1))
     (n, k) not in m (n, k) n k m d = int(n[0]) d int(n[0]) int n[0] n 0 m[(n, k)] = sum(doit(n[1:] if i == d else '9' * (len(n) - 1), k - 1 if i > 0 else k, m) for i in range(d + 1)) m[(n, k)] m (n, k) n k sum(doit(n[1:] if i == d else '9' * (len(n) - 1), k - 1 if i > 0 else k, m) 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, m) 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 m return m[(n, k)] m[(n, k)] m (n, k) n k n n k k m m print(doit(input(), int(input()), {})) print doit(input(), int(input()), {}) doit input() input int(input()) int input() input {} def doit(n, k, m):
    if len(n) == 0 or k < 0:
        return k == 0
    if (n, k) not in m:
        d = int(n[0])
        m[(n, k)] = sum(doit(n[1:] if i == d else '9' * (len(n) - 1), k - 1 if i > 0 else k, m) for i in range(d + 1))
    return m[(n, k)] def doit(n, k, m):
    if len(n) == 0 or k < 0:
        return k == 0
    if (n, k) not in m:
        d = int(n[0])
        m[(n, k)] = sum(doit(n[1:] if i == d else '9' * (len(n) - 1), k - 1 if i > 0 else k, m) for i in range(d + 1))
    return m[(n, k)] doit
import sys
sys.setrecursionlimit(303)


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


print(doit(input(), int(input()), {}))
