from collections import Counter
import sys
x = input()
n = len(x)
a = []

for i in range(n-1):
    if x[i] == "T" and x[i+1] == "S":
        a.append(i+1)
    
a = [0] + a + [n]

ans = 0
for i in range(len(a)-1):
    q = a[i+1]-a[i]
    b = Counter(x[:q])
    ans += abs(b["S"] - b["T"])
    x = x[q:]
    
print(ans)