#include <bits/stdc++.h>
using namespace std;
int main(){ 
int count=0;
int res=0;
string s;
cin>>s;
for(char c:s){
if(c=='S')
  count++;
else if(c=='T')
  count--;
if(count<0){
  res++;
  count=0;
}
}
 cout<<2*res<<endl;
}
