X = input()
N = len(X)
f = 0
h, e = 0, 0
for k in range(N):
    if X[k] == "S":
        h = k
        break
for k in range(N-1,-1,-1):
    if X[k] == "T":
        e = k
        break
s, t = 0, 0
for k in range(h,e+1):
    if X[k] == "S":
        s += 1
    else:
        t += 1
print(N-2*min(s,t))
