#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, i, sn, tn, dic;
  bool rf = false;
  string x;
  cin >> x;
  n = x.size();
  i = 0;
  dic = 0;
  while (i < n) {
    if (!rf) sn = 0;
    tn = 0;
    while (i < n && x[i] == 'S') {
      i++;
      sn++;
    }
    while (i < n && x[i] == 'T') {
      i++;
      tn++;
    }
    dic += min(sn, tn);
    if (sn > tn) rf = true;
  }
  cout << n - dic * 2 << endl;
  return 0;
}
