S = input()

count = len(S)
N = count
s_count = 0
t_count = 0

i = 0
while i < N:
    if S[i] == 'S':
        s_count += 1
        i += 1
    else:
        if s_count != 0:
            tmp = i
            while tmp < N and S[tmp] == 'T':
                tmp += 1
                t_count += 1
            cut = min(s_count, t_count)
            count -= cut*2
            s_count = t_count = 0
            i += cut
        else:
            i += 1

        
print(count)
