from sys import stdin
import numpy as np
X = (stdin.readline().rstrip())
cnt_t = 0
cnt_s = 0
cumsum_t = [0] * len(X)
cumsum_s = [0] * len(X)
for ind,i in enumerate(X):
    if i == "S":
        cnt_s += 1
    else:
        cnt_t += 1
    cumsum_s[ind] = cnt_s
    cumsum_t[ind] = cnt_t

ans = 0
for j in (np.array(cumsum_s) - np.array(cumsum_t)):
    if j < 0:
        ans += 1
print(ans)