#include <iostream>
using namespace std;
int main(void){
 int i=0,j,k,tlen,slen=0,stlen=0;
 string s;
 cin >> s;
 for(;(s[i]=='T')&&(i<s.length());i++){}
 while(i<s.length()){
  j=i;
  for(;(s[i]=='S')&&(i<s.length());i++){}
  slen+=i-j;
  k=i;
  for(;(s[i]=='T')&&(i<s.length());i++){}
  tlen=i-k;
  if(slen>tlen){
   stlen+=tlen*2;
   slen=slen-tlen;
  }else{
   stlen+=slen*2;
   slen=0
  }
 }
 cout << s.length()-stlen;
}