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