from math import factorial





def nCr(n, r):

    if r <= 0:

        return 0



    if n >= r:

        return factorial(n) // (factorial(n - r) * factorial(r))

    else:

        return 0



def main():

    N = eval(input())

    K = int(eval(input()))



    ans = func(N, K)



    print(ans)



def func(N, K):

    N = N.lstrip('0')

    if len(N) < K:

        return 0



    if K == 0:

        return 1



    n = int(N[0])



    if len(N) == 1:

        if K > 1:

            return 0

        else:

            return n



    ret = 0

    if K > 1:

        ret += func(N[1:], K-1)

    else:

        ret += 1

    l = len(N[1:])



    ret += (n - 1) * func('9' * l, K - 1)

    if l >= K:

        ret += func('9'* l, K)



    # ret += (n - 1) * nCr(l-1, K - 2) * 9 ** (K - 1)

    # ret += nCr(l-1, K - 1) * 9 ** K 



    return ret

    



if __name__ == '__main__':

    main()
from math import factorial





def nCr(n, r):

    if r <= 0:

        return 0



    if n >= r:

        return factorial(n) // (factorial(n - r) * factorial(r))

    else:

        return 0



N = eval(input())

K = int(eval(input()))



def rec(n, k, smaller):

    n = n.lstrip('0')



    if k == 0:

        return 1



    if len(n) < k:

        return 0



    if k == 1:

        if len(n) == 1:

            return int(n)





    if smaller:

        return nCr(len(n), k) * 9 ** k





    ret = 0

    ret += rec(n[1:], k-1, False)

    ret += rec('9'*(len(n)-1), k-1, True) * (int(n[0]) - 1)

    ret += rec('9'*(len(n)-1), k, True)



    return ret

    

ans = rec(N, K, False)

print(ans)



from math import factorial


def nCr(n, r):
    if r <= 0:
        return 0
    if n >= r:
        return factorial(n) // (factorial(n - r) * factorial(r))
    else:
        return 0


def main():
    N = eval(input())
    K = int(eval(input()))
    ans = func(N, K)
    print(ans)


def func(N, K):
    N = N.lstrip("0")
    if len(N) < K:
        return 0
    if K == 0:
        return 1
    n = int(N[0])
    if len(N) == 1:
        if K > 1:
            return 0
        else:
            return n
    ret = 0
    if K > 1:
        ret += func(N[1:], K - 1)
    else:
        ret += 1
    l = len(N[1:])
    ret += (n - 1) * func("9" * l, K - 1)
    if l >= K:
        ret += func("9" * l, K)
    # ret += (n - 1) * nCr(l-1, K - 2) * 9 ** (K - 1)
    # ret += nCr(l-1, K - 1) * 9 ** K
    return ret


if __name__ == "__main__":
    main()

from math import factorial


def nCr(n, r):
    if r <= 0:
        return 0
    if n >= r:
        return factorial(n) // (factorial(n - r) * factorial(r))
    else:
        return 0


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


def rec(n, k, smaller):
    n = n.lstrip("0")
    if k == 0:
        return 1
    if len(n) < k:
        return 0
    if k == 1:
        if len(n) == 1:
            return int(n)
    if smaller:
        return nCr(len(n), k) * 9**k
    ret = 0
    ret += rec(n[1:], k - 1, False)
    ret += rec("9" * (len(n) - 1), k - 1, True) * (int(n[0]) - 1)
    ret += rec("9" * (len(n) - 1), k, True)
    return ret


ans = rec(N, K, False)
print(ans)

-def main(): -    N = eval(input()) -    K = int(eval(input())) -    ans = func(N, K) -    print(ans) +N = eval(input()) +K = int(eval(input())) -def func(N, K): -    N = N.lstrip("0") -    if len(N) < K: +def rec(n, k, smaller): +    n = n.lstrip("0") +    if k == 0: +        return 1 +    if len(n) < k: -    if K == 0: -        return 1 -    n = int(N[0]) -    if len(N) == 1: -        if K > 1: -            return 0 -        else: -            return n +    if k == 1: +        if len(n) == 1: +            return int(n) +    if smaller: +        return nCr(len(n), k) * 9**k -    if K > 1: -        ret += func(N[1:], K - 1) -    else: -        ret += 1 -    l = len(N[1:]) -    ret += (n - 1) * func("9" * l, K - 1) -    if l >= K: -        ret += func("9" * l, K) -    # ret += (n - 1) * nCr(l-1, K - 2) * 9 ** (K - 1) -    # ret += nCr(l-1, K - 1) * 9 ** K +    ret += rec(n[1:], k - 1, False) +    ret += rec("9" * (len(n) - 1), k - 1, True) * (int(n[0]) - 1) +    ret += rec("9" * (len(n) - 1), k, True) -if __name__ == "__main__": -    main() +ans = rec(N, K, False) +print(ans)