program AGC005A
    implicit none
    integer(8)::i,xlen,flg,scount,tcount,ans
    character(200000)::X
    read*,X
    xlen=len_trim(X)
    ans=xlen
    flg=0
    scount=0
    tcount=0

    do i=1,xlen
        if(flg==0)then
            if(X(i:i)=="S")then
                scount=scount+1
            else
                tcount=1
                flg=1
            end if
        else
            if(X(i:i)=="S")then
                flg=0
                ans=ans-2*min(scount,tcount)
                scount=1
                tcount=0
            else
                tcount=tcount+1
            end if
        end if
    end do
    ans=ans-2*min(scount,tcount)
    print'(i0)',ans
end program AGC005A