x = input()
ans = len(x)
s = 0
t = 0
tar = "S"

for c in x:
    if c == "S":
        if tar == "T":
            ans -= min(s,t)*2
            s,t = 0,0
        s += 1
    else:
        t += 1
    tar = c
else:
    if tar == "T":
        ans -= min(s,t)*2

print(ans)