X = input()
S_cnt = T_cnt = T_all_cnt = 0
ans = 0

remain = len(X)
for x in X:
    if x == "S":
        S_cnt += 1
    else:
        T_cnt += 1
        T_all_cnt += 1
    if T_cnt > S_cnt:
        ans += 1
        T_cnt = max(T_cnt-1, 0)
    remain -= 1
    if T_all_cnt == len(X)//2:
        break

print(ans + remain)