N = int(input())
K = int(input())
def dp(n, k): #0以上n以下の数で０でない数字がちょうどk個あるもの。
  if n == 0 and k == 0:
    return 1
  else:
    n = int(n)
    s = str(n)
    digit = len(s)
    fdigit = int(s[-1])
    m = int((n - fdigit)/10)
    if m >= 1 and k >= 1:
        return int(dp(m, k-1) * fdigit + dp(m-1, k-1)* (9-fdigit) + dp(m, k))
    elif m >=1 and k == 0:
        return 1
    elif k == 1:
        return n
    elif k == 2 or k == 3:
        return 0
    else:
        return 1
if K == 0:
    answer = dp(N, K)-1
else:
    answer = dp(N, K)
print(int(answer))
