main :: IO ()
main = do
    s <- getLine
    print $ solve s (10 ^ 10000)

solve :: String -> Int -> Int
solve cs x = g $ foldr f (Nothing, [], False) cs
  where
    f 'S' (Just 'T', s, x) = (Nothing,     s, True)
    f  c  (Just d,   s, x) = (Just c,  d : s,    x)
    f  c  (Nothing,  s, x) = (Just c,      s,    x)
    g (Just  _, s, False) = length s + 1
    g (Nothing, s, False) = length s
    g (Just  c, s, True)  = solve (c : s) (pred x)
    g (Nothing, s, True)  = solve      s  (pred x)
