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

    read*, x
    n = len_trim(x)
    allocate(cnt(0:n), source=0)
    ans = n
    do i=1, n
        if (x(i:i) == 'S') then
            cnt(i)=cnt(i-1)+1
        else
            cnt(i)=max(cnt(i-1)-1,0)
            if (cnt(i-1) >= 1) ans=ans-2
        end if
    end do
    ! print'(*(i0,1x))', cnt(:)
    print'(i0)', ans
end program agc005_a