s=list(input())
n=len(s)
from collections import deque
q=deque([])
h=[1]*n
for i in range(n-1):
    if s[i]=='S' and s[i+1]=='T':
        q.append((i,i+1))
while q:
    l,r=q.popleft()
    h[l]=0
    h[r]=0
    while True:
        l-=1
        r+=1
        if 0<=l and r<n and (s[l]=='S' and s[r]=='T') and (h[l]!=0 and h[r]!=0):
            h[l]=0
            h[r]=0
        else:
            break
print(sum(h))