#include <bits/stdc++.h>
using namespace std;
int main() {
  string X;
  cin >> X;
  const int len = X.length();
  int ans = len;
  int offset = 0;
  for (int pos; (pos = X.find('S', offset)) != X.npos;) {
    int numS = 0;
    int numT = 0;
    while (pos < len && X[pos] == 'S') {
      ++numS;
      ++pos;
    }
    while (pos < len && X[pos] == 'T' && numT < numS) {
      ++numT;
      ++pos;
    }
    ans -= numT * 2;
    offset = pos;
  }
  cout << ans << endl;
}
