#include <bits/stdc++.h>
using namespace std;
int main() {
  string x;
  cin >> x;
  int s = 0, t = 0, cnt = 0;
  for (int i = 0; i < x.size(); i++) {
    if (x[i] == 'S' && t == 0)
      s++;
    else if (x[i] == 'T' && s != 0) {
      t++;
    }
    if (s != 0 && t != 0) {
      if (x[i] == 'S' || s == t) {
        cnt += min(s, t);
        if (x[i] == 'S')
          s = 1;
        else
          s = 0;
        t = 0;
      }
    }
  }
  cnt += min(s, t);
  cout << x.size() - cnt * 2 << endl;
  return 0;
}
