X = input()
N = len(X)
cnt_h = 0
for i in range(N):
    if X[i] == "S":
        cnt_h = i
        break
cnt_f = N
for i in range(N - 1, cnt_h, -1):
    if X[i] == "T":
        cnt_f = i + 1
        break
ans = 0
for i in range(cnt_h, cnt_f):
    if X[i] == "S":
        ans += 1
    else:
        ans -= 1
print(abs(ans) + cnt_h + N - cnt_f)
