x=list(input())
n=len(x)
word=[('S','S'),('S','T'),('T','T'),('T','S')]

if x[0]=='S':
  cnt_t=0
  cnt_s=1
else:
  cnt_t=1
  cnt_s=0

ans=0
for i in range(n-1):
    if (x[i],x[i+1])==word[0]:
      cnt_s+=1
    elif (x[i],x[i+1])==word[1]:
      cnt_t+=1
    elif (x[i],x[i+1])==word[2]:
      cnt_t+=1
    else:
      ans+=max(cnt_t,cnt_s)-min(cnt_t,cnt_s)
      cnt_s=1
      cnt_t=0

ans+=max(cnt_t,cnt_s)-min(cnt_t,cnt_s)
print(ans)
      