# https://atcoder.jp/contests/agc005/tasks/agc005_a

x = input()
i = 0
s = 0
t = 0
ans = len(x)
f = True
while i < len(x):
    if f:
        if x[i] == 'S':
            s += 1
            i += 1
        else:
            f = False
    else:
        if x[i] == 'T':
            i += 1
            t += 1
        else:
            ans -= min(s, t) * 2
            s = 0
            t = 0
            f = True
else:
    ans -= min(s, t) * 2
print(ans)