#include <bits/stdc++.h>
using namespace std;
int main() {
  string X;
  cin >> X;
  int cnt = 0;
  int sc = 0;
  int tc = 0;
  for (int i = 0; i < X.size(); i++) {
    while (X[i] == 'S') {
      sc++;
      i++;
      if (i == X.size()) break;
    }
    if (i == X.size()) break;
    while (X[i] == 'T') {
      tc++;
      i++;
      if (i == X.size()) break;
    }
    if (i == X.size()) break;
    i--;
    cnt += min(sc, tc);
    sc = 0;
    tc = 0;
  }
  cnt += min(sc, tc);
  cout << X.size() - 2 * cnt << endl;
  return 0;
}
