#include <bits/stdc++.h>
using namespace std;
int main() {
  string X;
  cin >> X;
  int res = 0;
  int nS = 0, nT = 0;
  auto n = X.size();
  int i = 0;
  while (i < n) {
    if (X[i] == 'S') {
      nT = 0;
      while (i < n && X[i] == 'S') {
        i++;
        nS++;
      }
    } else {
      while (i < n && X[i] == 'T') {
        i++;
        nT++;
      }
      res += 2 * min(nS, nT);
      nS = 0;
      nT = 0;
    }
  }
  cout << (n - res) << endl;
  return 0;
}
