x = input()

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

ans -= min(s, t) * 2

print(ans)