import streams, sequtils, strutils, algorithm, math, future, sets, tables, hashes
proc `ceilDiv`*[T](x, y: T): T = x div y + ord(x mod y != 0)
proc `//=`*(x: var SomeInteger; y: SomeInteger) = x = x div y
proc `%=`*(x: var SomeInteger; y: SomeInteger) = x = x mod y

var
    X = stdin.readLine
    T = newSeq[int]()
    S = newSeq[int]()
    ans = X.len
T.add 0
S.add 0
for i in 0..X.len-1:
    if X[i] == 'S':
        S.add S[^1] + 1
    else:
        S.add S[^1]
for i in countdown(X.len-1, 0, 1):
    if X[i] == 'T':
        T.add T[^1] + 1
    else:
        T.add T[^1]
S = S[1..X.len]
T.reverse
T = T[0..<X.len]
for i in 0..X.len-2:
    if X[i] == 'S' and X[i+1] == 'T':
        ans -= min(T[i+1], S[i+1]) * 2
        # echo min(T[i+1], S[i+1])
echo ans