x = input()
l = len(x)
s = 0
t = 0
for i in range(l):
    if x[i] == 'S':
        t = x[i+1:].count('T')
        break
for i in range(1, l+1):
    if x[-i] == 'T':
        s = x[:-i].count('S')
        break
print(l-min(s, t)*2)