from functools import lru_cache



N = eval(input())

K = int(eval(input()))



@lru_cache(maxsize=None)

def search(d, cnt, isEq):

    if d == len(N):

        return 1 if cnt == K else 0



    n = int(N[d])



    if isEq and n == 0:

        return search(d + 1, cnt, isEq)



    if isEq:

        ret = 0

        ret += search(d + 1, cnt, False)

        for _ in range(1, n):

            ret += search(d + 1, cnt + 1, False)

        ret += search(d + 1, cnt + 1, True)

        return ret



    return search(d + 1, cnt, False) + search(d + 1, cnt + 1, False) * 9



print((search(0, 0, True)))

from functools import lru_cache



N = eval(input())

K = int(eval(input()))



@lru_cache(maxsize=None)

def search(d, k, isLess):

    if k == K:

        return 1

    if d == len(N):

        return 0



    n = int(N[d])



    if isLess:

        return search(d + 1, k, isLess) + search(d + 1, k + 1, isLess) * 9



    ret = 0

    for i in range(n + 1):

        ret += search(d + 1, k + (1 if i > 0 else 0) , isLess or (i < n))

    return ret



print((search(0, 0, False)))

from functools import lru_cache

N = eval(input())
K = int(eval(input()))


@lru_cache(maxsize=None)
def search(d, cnt, isEq):
    if d == len(N):
        return 1 if cnt == K else 0
    n = int(N[d])
    if isEq and n == 0:
        return search(d + 1, cnt, isEq)
    if isEq:
        ret = 0
        ret += search(d + 1, cnt, False)
        for _ in range(1, n):
            ret += search(d + 1, cnt + 1, False)
        ret += search(d + 1, cnt + 1, True)
        return ret
    return search(d + 1, cnt, False) + search(d + 1, cnt + 1, False) * 9


print((search(0, 0, True)))

from functools import lru_cache

N = eval(input())
K = int(eval(input()))


@lru_cache(maxsize=None)
def search(d, k, isLess):
    if k == K:
        return 1
    if d == len(N):
        return 0
    n = int(N[d])
    if isLess:
        return search(d + 1, k, isLess) + search(d + 1, k + 1, isLess) * 9
    ret = 0
    for i in range(n + 1):
        ret += search(d + 1, k + (1 if i > 0 else 0), isLess or (i < n))
    return ret


print((search(0, 0, False)))

-def search(d, cnt, isEq): +def search(d, k, isLess): +    if k == K: +        return 1 -        return 1 if cnt == K else 0 +        return 0 -    if isEq and n == 0: -        return search(d + 1, cnt, isEq) -    if isEq: -        ret = 0 -        ret += search(d + 1, cnt, False) -        for _ in range(1, n): -            ret += search(d + 1, cnt + 1, False) -        ret += search(d + 1, cnt + 1, True) -        return ret -    return search(d + 1, cnt, False) + search(d + 1, cnt + 1, False) * 9 +    if isLess: +        return search(d + 1, k, isLess) + search(d + 1, k + 1, isLess) * 9 +    ret = 0 +    for i in range(n + 1): +        ret += search(d + 1, k + (1 if i > 0 else 0), isLess or (i < n)) +    return ret -print((search(0, 0, True))) +print((search(0, 0, False)))