#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
  string s;
  cin>>s;
  ll a=0,b=0,sum=0,n=s.size();
  bool flag=false;
  for(int i=0;i<n-1;i++){
    if(s[i]=='S'&&s[i+1]=='S') a++;
    else if(s[i]=='S'&&s[i+1]=='T') a++;
    else if(s[i]=='T'&&s[i+1]=='T') b++;
    else{
      b++;
      sum+=min(a,b);
      a=max(0,a-b);
      b=0;
    }
  }
  sum+=min(a,b);
  cout<<n-2*sum;
}
