x = input()
ans = len(x)
cnt = {"S":0,"T":0}
tar = "S"

for c in x:
    if c == "S" and tar == "T":
        ans -= min(cnt.values())*2
        cnt = {"S":0,"T":0}
    cnt[c] +=  1
    tar = c
else:
    if tar == "T":
        ans -= min(cnt.values())*2
        
print(ans)