package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	s := Scanner()
	x := make([][]byte, 1)
	x[0] = []byte{s[0]}
	for i := 1; i < len(s); i++ {
		if s[i] == x[len(x)-1][0] {
			x[len(x)-1] = append(x[len(x)-1], s[i])
		} else {
			x = append(x, []byte{s[i]})
		}
	}
	if len(x) == 1 {
		fmt.Println(len(x))
	} else {
		ans := 0
		if string(x[0][0]) == "T" {
			ans += len(x[0])
			x = x[1:]
		}
		if string(x[len(x)-1][0]) == "S" {
			ans += len(x[len(x)-1])
			x = x[:len(x)-1]
		}
		rem := 0
		for i := 0; i < len(x); i += 2 {
			a, b := len(x[i]), len(x[i+1])
			if a+rem > b {
				rem = a + rem - b
			} else if a+rem < b {
				ans += b - a - rem
			}
		}
		fmt.Println(ans + rem)
	}
}
