#include <bits/stdc++.h>
using namespace std;
const int N=5e5;

  int n,z,A;
  char s[N];
int main()
{
  scanf("%s",s);
  n=strlen(s);
  for (int i=n;~--i;)
    if (s[i]=='T') ++z;
    else A+=!!z*2,z=max(z-1,0);
  cout<<n-A;
  exit(0);
}