program A819B
    implicit none
    integer(8)::i,ans,Nlen
    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

    if(ans==A(1)+9*(Nlen-1))then
        print'(i0)',ans
    else
        print'(i0)',A(1)+9*(Nlen-1)-1
    end if
end program A819B