import Data.List

main=print =<< solve "" <$> getLine

solve s ""
    | f s = solve "" s
    | otherwise = length s

solve s x
    | ns == 0 = solve (s++takeWhile (=='T')x) (dropWhile(=='T')x)
    | ns>nt   = solve (s++replicate (ns-nt) 'S') xr
    | ns<nt   = solve (s++replicate (nt-ns) 'T') xr
    | otherwise = solve s xr
    where
        ns = length $ takeWhile (=='S') x
        nt = length $ takeWhile (=='T') $ dropWhile (=='S') x
        xr = dropWhile (=='T') $ dropWhile (=='S') x

f x = case elemIndex 'S' x of
            Nothing -> False
            Just i | i < length x -1 -> (x !! (i+1)) == 'T'
            _ -> False