program A819B
    implicit none
    integer(8)::i,j,ans,Nlen,calc
    character(16)::N
    integer(8),allocatable,dimension(:)::A
    read*,N
    Nlen=len_trim(N)
    ans=0
    allocate(A(Nlen))
    do i=1,Nlen
        A(i)=ichar(N(i:i))-48
        ans=ans+A(i)
    end do

    do i=1,Nlen
        calc=0
        do j=1,Nlen
            if(j<i)calc=calc+A(j)
            if(j==i)calc=calc+A(j)-1
            if(j>i)calc=calc+9
        end do
        ans=max(ans,calc)
    end do

    print'(i0)',ans
end program A819B