import math
import numpy as np

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

def aez(N, K):
    digits = math.floor(math.log10(N)) + 1
    LD = N // 10**(digits-1)
    
    if K == 1:
        return (digits - 1) * 9 + LD
    
    if digits < K:
        return 0
    A = aez(10 ** (digits  - 1) - 1 , K)
    B = aez(10 ** (digits  - 1) - 1, K - 1) * (LD - 1)
    C = aez(N % (10 ** (digits  - 1)), K - 1)
    count = A + B + C
    
    return count
  
print(aez(N, K))

