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