from collections import deque

X = deque(list(input()))
ans = len(X)

#頭のTを読み捨てる
while 1:
    #print(X)
    if X[0] == "T":
        X.popleft()
    else:
        X.popleft()
        S_cnt = 1
        T_cnt = 0
        mode = "S"
        break
        
    if len(X) == 0:
        break

#Sが出てきて以後の処理
if mode == "S":
    while 1:
        #print(X,T_cnt,S_cnt)
        if len(X) == 0:
            ans -= 2*min(S_cnt,T_cnt)
            break
        elif mode == "S":
            if X[0] == "T":
                X.popleft()
                mode = "T"
                T_cnt = 1
            else:
                X.popleft()
                S_cnt += 1
        elif mode == "T":
            if X[0] == "T":
                X.popleft()
                T_cnt += 1
            else:
                ans -= 2*min(S_cnt,T_cnt)
                X.popleft()
                mode = "S"
                T_cnt = 0
                S_cnt = 1
        
print(ans)