from sys import stdin
from itertools import groupby

s = list(stdin.readline().rstrip())
S = len(s)

li = []
for key, value in groupby(s):
    li.append((key,len(list(value))))

point = 0
amari = 0

for i in range(len(li)-1):
    if li[i][0] == "S" and li[i+1][0] == "T":
        point += min(li[i][1]+amari,li[i+1][1])
        amari = max(li[i][1]+amari,li[i+1][1]) - min(li[i][1]+amari,li[i+1][1])
print(S-point*2)