import java.util.Scanner

object Main extends App  {
  val sc = new Scanner(System.in)

  val iS = sc.next

  val s = iS + "Z"

  val temp =
    s.foldLeft(("","")){case( (str, stack), ch) =>
      ch match{
        case 'S'                  => (str, ch +: stack)
        case 'T' if stack.isEmpty => (str + ch, stack)
        case 'T'                  => (str, stack.tail)
        case _   => (str + stack, "")
      }
    }._1

  val res = temp.length
  
  println(res)
}
