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