N = int(input())
K = int(input())
from math import log10
from operator import mul
from functools import reduce

def comb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


lg = int(log10(N))

def dp(n:int,k:int,K:int):
    lg = int(log10(N))
    if n > N:
        return 0
    if k > K:
        return 0
    if k == K:
        tmp = lg - int(log10(n))
        return tmp if n*10**tmp > N else tmp + 1
    sm = 0
    for i in range(1,10):
        sm += dp(n*10 + i,k + 1,K)
    return sm + dp(n*10,k,K)

memo = {}
def dp2(string:str,k:int):
    if (string,k) in memo:
        return memo[(string,k)]
    if k == 1:
        ans = 0
        for i in range(int( log10( N ) ) + 2):
            digit = 10**i
            for j in range(1,10):
                if j*digit <= N:
                    ans += 1
        memo[(string,k)] = ans
        return memo[(string,k)]

    if string[0] == "0":
        memo[(string,k)] =  dp2(string[1:],k)
        return memo[(string,k)]

    if len(string) > 3:
        ln = len(string)
        tmp = (comb(ln - 1,k)*9**k)*(string[0]) + dp2(string[1:],k)
        memo[(string,k)] = tmp
        return tmp
    memo[(string,k)] = dp(int(string),0,K)
    return memo[(string,k)]

def main():
    if K == 1:
        ans = 0
        for i in range(int( log10( N ) ) + 2):
            digit = 10**i
            for j in range(1,10):
                if j*digit <= N:
                    ans += 1
        print(ans)
        return
    if N < 10**10:
        ans = 0
        for i in range(1,10):
            ans += dp(i,1)
        print(ans)
    print(dp2(str(N),K))
    return

if __name__ == "__main__":
    main()