s = input()
s_cnt, t_cnt = 0, 0
n = len(s)
for i in range(n):
    if s[i] == "S":
        for j in range(i, n):
            if s[j] == "T":
                t_cnt += 1
        
        break

for i in range(n - 1, -1, -1):
    if s[i] == "T":
        for j in range(i, -1, -1):
            if s[j] == "S":
                s_cnt += 1
        break
print(n - min(t_cnt, s_cnt) * 2)