# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
from itertools import combinations, product
#import bisect# lower_bound etc
#import numpy as np
def run():
    N,K = map(int, read().split())
    k = int(math.log(N, 10))
    s = N // (10 ** k)

    tmp1, tmp2, div = 1, 1, 1
    for i in range(K-1):
        tmp1 *= k-i
        div *= i+1
        tmp2 *= 9
    ret = tmp1//div * tmp2
    ret *= s-1

    tmp1 *= k - (K-1)
    tmp2 *= 9
    div *= K

    ret += tmp1 * tmp2 // div
    lis = range(k)
    nums = range(1,10)
    base = s * 10 ** k

    for A in combinations(lis, K-1):
        for X in product(nums, repeat = K-1):
            tmp = base
            for a,x in zip(A,X):
                tmp += 10 ** a * x
            if tmp <= N:
                ret += 1
    print(ret)



if __name__ == "__main__":
    run() import sys sys sysread = sys.stdin.readline sysread sys.stdin.readline sys.stdin sys stdin readline read = sys.stdin.read read sys.stdin.read sys.stdin sys stdin read sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 import math math from itertools import combinations, product def run():
    N,K = map(int, read().split())
    k = int(math.log(N, 10))
    s = N // (10 ** k)

    tmp1, tmp2, div = 1, 1, 1
    for i in range(K-1):
        tmp1 *= k-i
        div *= i+1
        tmp2 *= 9
    ret = tmp1//div * tmp2
    ret *= s-1

    tmp1 *= k - (K-1)
    tmp2 *= 9
    div *= K

    ret += tmp1 * tmp2 // div
    lis = range(k)
    nums = range(1,10)
    base = s * 10 ** k

    for A in combinations(lis, K-1):
        for X in product(nums, repeat = K-1):
            tmp = base
            for a,x in zip(A,X):
                tmp += 10 ** a * x
            if tmp <= N:
                ret += 1
    print(ret) run N,K = map(int, read().split()) N map(int, read().split()) map int read().split() ().split () read split K k = int(math.log(N, 10)) k int(math.log(N, 10)) int math.log(N, 10) math.log math log N 10 s = N // (10 ** k) s N // (10 ** k) N 10 ** k 10 k tmp1, tmp2, div = 1, 1, 1 tmp1 1 tmp2 1 div 1 for i in range(K-1):
        tmp1 *= k-i
        div *= i+1
        tmp2 *= 9
     i range(K-1) range K-1 K 1 tmp1 *= k-i tmp1 k-i k i div *= i+1 div i+1 i 1 tmp2 *= 9 tmp2 9 ret = tmp1//div * tmp2 ret tmp1//div * tmp2 tmp1//div tmp1 div tmp2 ret *= s-1 ret s-1 s 1 tmp1 *= k - (K-1) tmp1 k - (K-1) k K-1 K 1 tmp2 *= 9 tmp2 9 div *= K div K ret += tmp1 * tmp2 // div ret tmp1 * tmp2 // div tmp1 * tmp2 tmp1 tmp2 div lis = range(k) lis range(k) range k nums = range(1,10) nums range(1,10) range 1 10 base = s * 10 ** k base s * 10 ** k s 10 ** k 10 k for A in combinations(lis, K-1):
        for X in product(nums, repeat = K-1):
            tmp = base
            for a,x in zip(A,X):
                tmp += 10 ** a * x
            if tmp <= N:
                ret += 1
     A combinations(lis, K-1) combinations lis K-1 K 1 for X in product(nums, repeat = K-1):
            tmp = base
            for a,x in zip(A,X):
                tmp += 10 ** a * x
            if tmp <= N:
                ret += 1
     X product(nums, repeat = K-1) product nums repeat = K-1 repeat K-1 K 1 tmp = base tmp base for a,x in zip(A,X):
                tmp += 10 ** a * x
             a x zip(A,X) zip A X tmp += 10 ** a * x tmp 10 ** a * x 10 ** a 10 a x if tmp <= N:
                ret += 1
     tmp <= N tmp N ret += 1 ret 1 print(ret) print ret if __name__ == "__main__":
    run() __name__ == "__main__" __name__ "__main__" run() run def run():
    N,K = map(int, read().split())
    k = int(math.log(N, 10))
    s = N // (10 ** k)

    tmp1, tmp2, div = 1, 1, 1
    for i in range(K-1):
        tmp1 *= k-i
        div *= i+1
        tmp2 *= 9
    ret = tmp1//div * tmp2
    ret *= s-1

    tmp1 *= k - (K-1)
    tmp2 *= 9
    div *= K

    ret += tmp1 * tmp2 // div
    lis = range(k)
    nums = range(1,10)
    base = s * 10 ** k

    for A in combinations(lis, K-1):
        for X in product(nums, repeat = K-1):
            tmp = base
            for a,x in zip(A,X):
                tmp += 10 ** a * x
            if tmp <= N:
                ret += 1
    print(ret) def run():
    N,K = map(int, read().split())
    k = int(math.log(N, 10))
    s = N // (10 ** k)

    tmp1, tmp2, div = 1, 1, 1
    for i in range(K-1):
        tmp1 *= k-i
        div *= i+1
        tmp2 *= 9
    ret = tmp1//div * tmp2
    ret *= s-1

    tmp1 *= k - (K-1)
    tmp2 *= 9
    div *= K

    ret += tmp1 * tmp2 // div
    lis = range(k)
    nums = range(1,10)
    base = s * 10 ** k

    for A in combinations(lis, K-1):
        for X in product(nums, repeat = K-1):
            tmp = base
            for a,x in zip(A,X):
                tmp += 10 ** a * x
            if tmp <= N:
                ret += 1
    print(ret) run sysread = sys.stdin.readline sys.stdin.readline sysread read = sys.stdin.read sys.stdin.read read
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
from itertools import combinations, product
#import bisect# lower_bound etc
#import numpy as np
def run():
    N,K = map(int, read().split())
    k = int(math.log(N, 10))
    s = N // (10 ** k)

    tmp1, tmp2, div = 1, 1, 1
    for i in range(K-1):
        tmp1 *= k-i
        div *= i+1
        tmp2 *= 9
    ret = tmp1//div * tmp2
    ret *= s-1

    tmp1 *= k - (K-1)
    tmp2 *= 9
    div *= K

    ret += tmp1 * tmp2 // div
    lis = range(k)
    nums = range(1,10)
    base = s * 10 ** k

    for A in combinations(lis, K-1):
        for X in product(nums, repeat = K-1):
            tmp = base
            for a,x in zip(A,X):
                tmp += 10 ** a * x
            if tmp <= N:
                ret += 1
    print(ret)



if __name__ == "__main__":
    run()