x=input()
n=len(x)
s=[0]*n
t=[0]*n
s[0]=(x[0]=='S')*1
t[0]=(x[0]=='T')*1
for i in range(1,n):
  if x[i]=='S':
    s[i]=s[i-1]+1
    t[i]=t[i-1]
  if x[i]=='T':
    s[i]=s[i-1]
    t[i]=t[i-1]+1
  if x[i-1]=='T' and x[i]=='S':
    s[i]=1;t[i]=0
c=0
t0=0
for i in range(n):
  if t[i]==0:
    t0+=1
  else:
    t0=0
  if s[i]>=t[i]:
    c+=1
print(n-c+t0)