n = int(input())
k = int(input())
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result
def cnt(i):
  c = 0
  for l in str(i):
    if l != "0":
      c += 1
  return c
if n < 1000:
  q = 0
  for i in range(1,n+1):
    if cnt(i) == k:
      q += 1
  print(q)
  quit()
if k == 1:
  print(9*(len(str(n))-1)+int(str(n)[0]))
if k == 2:
  ans = 0
  top = int(str(n)[0])
  if top > 1:
    ans += (top-1)*(9*(len(str(n))-1))
  ans += cmb(len(str(n))-1,2)*81
  n = n - top*10**(len(str(n))-1)
  ans += 9*(len(str(n))-1)+int(str(n)[0])
  print(ans)
  quit()

#k==3
ans = 0
top = int(str(n)[0])
if top > 1:
  ans += (top-1)*cmb(len(str(n))-1,2)*81
ans += cmb(len(str(n))-1,3)*729
n = n - top*10**(len(str(n))-1)
top = int(str(n)[0])
if top > 1:
  ans += (top-1)*(9*(len(str(n))-1))
ans += cmb(len(str(n))-1,2)*81
n = n - top*10**(len(str(n))-1)
ans += 9*(len(str(n))-1)+int(str(n)[0])
print(ans)