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