import sys
 
stdin = sys.stdin

mod = 1000000007
inf = 1 << 60
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

x = ns()
n = len(x)

ans = n
i = 0
while i < n:
    cs = 0
    ct = 0
    while i < n and x[i] == 'S':
        cs += 1
        i += 1
    while i < n and x[i] == 'T':
        ct += 1
        i += 1
    ans -= min(cs, ct) * 2

print(ans)