x = input()
ans, count0, count1 = len(x), 0, 0
for i in x:
    if i == 'S' and count1 == 0:
        count0 += 1
    elif i == 'T':
        count1 += 1
    else:
       ans -= 2*min(count0, count1)
       if i == 'S':
           count0, count1 = 1, 0
       else:
           count0, count1 = 0, 0
ans -= 2*min(count0, count1)
print(ans)
