A=list(input())
now=1
S=0
T=0
ans=0
while now != len(A):
   if A[now] == "T":
      S=now-1
      T=now
      for i in range(len(A)):
         if A[S]=="S":
            S-=1
         if S < 0:
            break
      S=now-S-1
      for i in range(len(A)):
         if A[T]=="T":
            T+=1
         if T > len(A)-1:
            break
      T=T-now
      ans+=min(T,S)
      now+=T
   else:
      now+=1
print(len(A)-ans*2)