n=str(input())
k=int(input())
top=int(n[0])
l=len(n)
if k==1:
  print(9*(l-1)+top)
if k==2:
  if l==1:
    print(0)
  else:
    for i in range(1,l):
      result=0
      if l>2:
        result+=
      second=0
      second_i=0
      if n[i]!=0:
        second=n[i]
        second_i=i
        break