import sys
input = lambda: sys.stdin.readline().rstrip() 
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

def resolve():
    N = input()
    K = int(input())

    ans = 0
    # 最上桁が0のとき
    if len(N)-1 >= K:
        ans += combinations_count(len(N)-1, K) * 9**K
    # 最上桁が非0のとき
    updigit = int(N[0:K])
    counter = [0]*(K+1)
    if updigit >= int('1'*K):
        for i in range(int('1'+'0'*(K-1)), updigit+1):
            counter[str(i).count('0')] += 1
    for i, c in enumerate(counter):
        if len(N)-K >= i:
            ans += c * combinations_count(len(N)-K, i) * 9**i

    print(ans)

if __name__ == '__main__':
    resolve()
