program proA
  implicit none
  integer*8 n,i,ans,j,max,tmp,keta
  character(20) str

  read(*,*) n

  do j=0,16
     if(dble(n)<10**j) exit
  end do

  tmp=0
  keta=j
  j=j-1

  ans=n-10**j+1
  ans=ans/10**j+9*j
  write(*,*)ans
      
end program proA
