X = input()
st = 0
s = 0
t = 0
for x in X:
    if x == "S":
        st += min(s, t)
        s += 1
        if t > 0:
            s = 1
            t = 0
    elif x == "T" and s > 0:
        t += 1
st += min(s, t)
print(len(X) - 2 * st)