n = int(input())
k = int(input())

def combi(n, r):
  num = 1
  for i in range(1, r+1):
    num = num * (n - i + 1) // i
  return num

ans = 0

if len(str(n))<=k:
  for i in range(1, n+1):
    si = str(i)
    if len(si) - si.count('0') == k:
      ans += 1
  print(ans)
  exit(0)

# 0(k non 0 digits)
ln = len(str(n))
ans += combi(ln-1, k) * 9**k

sn = str(n)
ntopd = int(sn[0])

if k == 1:
  ans += ntopd
elif k == 2:
  for topd in range(1, ntopd):
    if topd < ntopd:
      ans += 9 * (ln - 1)
    elif topd == ntopd:
      for i in range(1, ln):
        ans += int(sn[i])
elif k == 3:
  for topd in range(1, ntopd):
    if topd < ntopd:
      ans += 9 * 9 * combi(ln-1, 2)
    elif topd == ntopd:
      for i in range(1, ln-1):
        for j in range(i+1, ln):
          snid = int(sn[i])
          if snid != 0:
            ans += int(sn[j]) + (snid - 1) * 9
print(ans)