import sys

sys.setrecursionlimit(10000)



n = eval(input())

k = int(eval(input()))

m = {}





def doit(n, k):

    if len(n) == 0:

        return k == 0

    d = int(n[0])

    if (n, k) not in m:

        ret = 0

        for i in range(d + 1):

            if i == d:

                ret += doit(n[1:], k - 1 if i > 0 else k)

            else:

                ret += doit('9' * (len(n) - 1), k - 1 if i > 0 else k)

        m[(n, k)] = ret

    return m[(n, k)]





print((doit(n, k)))

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(eval(input()), int(eval(input())), {})))

import sys

sys.setrecursionlimit(10000)
n = eval(input())
k = int(eval(input()))
m = {}


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


print((doit(n, k)))

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(eval(input()), int(eval(input())), {})))

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