program AGC005A
    implicit none
    integer(8)::i,xlen,sc,tc,ans
    character(200000)::X
    character(1),allocatable,dimension(:)::stack
    read*,X
    xlen=len_trim(X)
    allocate(stack(xlen))
    ans=xlen
    sc=1
    tc=1

    do i=1,xlen
        if(X(i:i)=="T")then
            if(tc-sc==0.or.stack(tc-1)=="T")then
                stack(tc)="T"
                tc=tc+1
            else if(stack(tc-1)=="S")then
                tc=tc-1
            end if
        else
            stack(tc)="S"
            tc=tc+1
        end if
    end do
    print'(i0)',tc-sc
end program AGC005A