#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
int main() {
  char S[200000];
  scanf("%s", S);
  int Scount = 0, Tcount = 0;
  int an = 0, i = 1;
  if (S[0] == 'S') Scount++;
  while (S[i] != '\0') {
    if (S[i] == 'S') {
      if (S[i - 1] == 'T') {
        an += 2 * min(Scount, Tcount);
        Scount = 0;
        Tcount = 0;
      }
      Scount++;
    } else if (S[i] == 'T') {
      Tcount++;
    }
    i++;
  }
  an += 2 * min(Scount, Tcount);
  printf("%d", i - an);
  return 0;
}
