import java.util.Scanner

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

  val iS = sc.next

  val s = (iS + "Z").toArray

  val temp =
    s.foldLeft(("".toArray,"".toArray)){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, Array())
      }
    }._1

  val res = temp.length

  println(res)
}
