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