x = input()

x = x.replace("ST", "")

ans = len(x)
s = 0
t = 0
f = 1
for xi in x:
    if xi == "S":
        if f:
            s += 1
        else:
            ans -= min(s, t) * 2
            s = 1
            t = 0
            f = 1
    if s and xi == "T":
        t += 1
        f = 0

ans -= min(s, t) * 2

print(ans)