X = list(input())

count_s = [0 for i in range(len(X))]
count_t = [0 for i in range(len(X))]

if X[0] == 'S':
    count_s[0] = 1
else:
    count_t[0] = 1

for i in range(1,len(X)):
    if X[i] == 'S':
        count_s[i] = count_s[i-1] + 1
        count_t[i] = count_t[i-1]
    else:
        count_t[i] = count_t[i-1] + 1
        count_s[i] = count_s[i-1]

t_index = count_t.index(max(count_t))
s_part_max = max(count_s[:t_index+1])
print(len(X) - min(max(count_t),s_part_max) * 2)