X = input()

cnt_s, cnt_t = 0, 0

if X[0] == 'S':
    cnt_s = 1
ans = 0
for i in range(1, len(X)):
    p = X[i - 1]
    c = X[i]
    if c == 'S':
        if p == 'T':
            ans += min(cnt_s, cnt_t) * 2
            cnt_s += 1
            cnt_t = 0
        else:
            cnt_s += 1
    if c == 'T':
        cnt_t += 1


ans += min(cnt_s, cnt_t) * 2
print(len(X) - ans)
