n = int(input())
k = int(input())
if k == 1:
  flag = True
  cnt = 0
  while flag:
    for i in range(101):
      for j in range(1,10):
        if j*(10**i) <= n:
          cnt += 1
        else:
          flag = False
          break
elif k == 2:
  flag = True
  cnt = 0
  while flag:
    for i in range(1,101):
      for j in range(1,10):
        for l in range(i):
          for m in range(1,10):
            if j*(10**i)+m*(10**l) <= n:
              cnt += 1
            else:
              flag = False
              break
else:
  flag = True
  cnt = 0
  while flag:
    for i in range(2,25):
      for j in range(1,10):
        for l in range(1,i):
          for m in range(1,10):
            for o in range(l):
              for p in range(1,10):
                if j*(10**i)+m*(10**l)+p*(10**o) <= n:
                  cnt += 1
                else:
                  flag = False
                  break
print(cnt)