s = input()
ans = len(s)
idx = s.index("S")
if idx == -1:
    print(ans)
    exit()
s_ = "S"
s_cnt = t_cnt = 0
while idx < len(s):
    if s_ == s[idx]:
        if s_ == "S":
            s_cnt += 1
        else:
            t_cnt += 1
    elif s_ == "S" and s[idx] == "T":
        s_ = "T"
        t_cnt += 1
    elif s_ == "T" and s[idx] == "S":
        ans -= min(s_cnt, t_cnt) * 2
        s_ = "S"
        s_cnt = 1
        t_cnt = 0
    idx += 1
if s_ == "T": ans -= min(s_cnt, t_cnt) * 2
print(ans)