#include <bits/stdc++.h>
using namespace std;
int main() {
  string ss;
  cin >> ss;
  bool cc = false;
  int brojac = ss.size();
  int s1 = 0, t1 = 0;
  bool imatt = true;
  for (int i = 0; i < ss.size(); i++) {
    if (ss[i] == 'S' && imatt) {
      brojac -= 2 * min(s1, t1);
      if (t1 == min(s1, t1))
        s1++, t1 = 0;
      else
        s1 = 1, t1 = 0;
      cc = true;
      imatt = false;
    } else if (ss[i] == 'S' && cc)
      s1++;
    else if (ss[i] == 'T' && cc) {
      t1++;
      imatt = true;
    }
  }
  brojac -= 2 * min(s1, t1);
  cout << brojac << endl;
  return 0;
}
