program prob4
    implicit none
    integer(8) :: N
    integer :: m

    read(*,*) N
    N = N + 1

    m = 0
    do while(N >= 10)
        N = N / 10
        m = m + 1
    end do

    write(*,*) 9*m + N - 1

    stop
contains
end program prob4