X = input()
ans = len(X)
N = len(X)
cnt_s = 0
cnt_t = 0
for i in range(N):
    if X[i] == "S":
        cnt_s += 1
    if X[i] == "T":
        cnt_t += 1
    if i < N -1:
        if X[i] == "T" and X[i + 1] == "S":
            ans -= 2 * min(cnt_s, cnt_t)
            cnt_s = 0
            cnt_t = 0
    else:
        ans -= 2 * min(cnt_s, cnt_t)
    
print(ans)