main = do
  x <- getLine
  print . length . g $ f x

f :: String -> String
f [] = []
f ('S':'T':xs) = f xs
f (x:xs) = x : f xs

g :: String -> String
g xs
  | length xs' < length xs = g xs'
  | otherwise = xs'
    where xs' = f xs