program sample
    implicit none
  
    integer(8) :: i,j,m,n,k
    real(8)::a,b
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) n
    n=n+1
    a=log10(real(n))
    m=int(a) !桁数-1
    k=m*9+n/10**m-1
    write(*,*) k
  
    stop
end program sample
  

