program agc005_a
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: i,n,l,r,cnt
    character(200000):: x

    read*, x
    n = len_trim(x)

    cnt = 0
    do i=1,n-1
        if (x(i:i+1) /= 'ST') cycle
        l = i
        r = i+1
        do while(x(l:l) == 'S' .and. x(r:r) == 'T')
            cnt=cnt+1
            l=l-1
            r=r+1
            if (l < 1 .or. n < r) exit
        end do
    end do

    print'(i0)', n-2*cnt
end program agc005_a