import math
def comb(n, r):
    if n == r:
      return 1
    else:
      return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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


def sasa(N, K):
  # 桁数を取得
  dig = len(str(N))
  top = int(str(N)[0])
  ans = 0
  # X00000までの場合
  # 先頭を0以外にする場合
  if dig-1>=K-1:
    ans += (top-1) * comb(dig-1, K-1) * 9**(K-1)

  # 先頭を0にする場合
  if dig-1 >= K:
    ans += comb(dig-1, K) * 9**K

  if K == 1:
    ans += 1
  return ans

if K == 1:
  N1 = round(N, -len(str(N)) + 1)
  print(sasa(N1, K))
  exit()

if K == 2:
  N1 = round(N, -len(str(N)) + 1)
  ans1 = sasa(N1,K)

  _N2 = N - N1
  N2 = round(_N2, -len(str(_N2)) + 1)
  ans2 = sasa(N2, K-1)
  print(ans1+ans2)
  exit()

if K == 3:
  N1 = round(N, -len(str(N)) + 1)
  ans1 = sasa(N1,K)

  _N2 = N - N1
  N2 = round(_N2, -len(str(_N2)) + 1)
  ans2 = sasa(N2, K-1)

  _N3 = N - N1 - N2
  N3 = round(_N3, -len(str(_N3)) + 1)
  ans3 = sasa(N3, K-2)

  print(ans1+ans2+ans3)
  exit()
