N = eval(input())

K = int(eval(input()))



def search(d, k, isLess):

    if k == K:

        return 1

    if d == len(N):

        return 0



    ret = search(d + 1, k, isLess or int(N[d]) > 0)



    if k < K:

        if isLess:

            ret += search(d + 1, k + 1, True) * 9

        elif int(N[d]) > 0:

            ret += search(d + 1, k + 1, True) * (int(N[d]) - 1) + search(d + 1, k + 1, False)



    return ret



ans = search(0, 0, False)

print(ans)
from functools import lru_cache



N = eval(input())

K = int(eval(input()))



@lru_cache(maxsize=None)

def search(d, cnt, isLess):

    if d == len(N):

        return cnt == K



    a = int(N[d])



    if isLess:

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



    ret = 0

    for i in range(a + 1):

        ret += search(d + 1, cnt + (i != 0), i < a)

    return ret



print((search(0, 0, False)))
N = eval(input())
K = int(eval(input()))


def search(d, k, isLess):
    if k == K:
        return 1
    if d == len(N):
        return 0
    ret = search(d + 1, k, isLess or int(N[d]) > 0)
    if k < K:
        if isLess:
            ret += search(d + 1, k + 1, True) * 9
        elif int(N[d]) > 0:
            ret += search(d + 1, k + 1, True) * (int(N[d]) - 1) + search(
                d + 1, k + 1, False
            )
    return ret


ans = search(0, 0, False)
print(ans)

from functools import lru_cache

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


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


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

+from functools import lru_cache + -def search(d, k, isLess): -    if k == K: -        return 1 +@lru_cache(maxsize=None) +def search(d, cnt, isLess): -        return 0 -    ret = search(d + 1, k, isLess or int(N[d]) > 0) -    if k < K: -        if isLess: -            ret += search(d + 1, k + 1, True) * 9 -        elif int(N[d]) > 0: -            ret += search(d + 1, k + 1, True) * (int(N[d]) - 1) + search( -                d + 1, k + 1, False -            ) +        return cnt == K +    a = int(N[d]) +    if isLess: +        return search(d + 1, cnt + 1, isLess) * 9 + search(d + 1, cnt, isLess) +    ret = 0 +    for i in range(a + 1): +        ret += search(d + 1, cnt + (i != 0), i < a) -ans = search(0, 0, False) -print(ans) +print((search(0, 0, False)))