#include <bits/stdc++.h>
using ll = long long;
using namespace std;
constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);
int main(void) {
  string x;
  cin >> x;
  int n = (int)x.size();
  int ans = n;
  int s = 0, t = 0;
  bool sflag = false, tflag = false;
  for (int i = 0; i < n; ++i) {
    if (x[i] == 'S') {
      if (tflag) {
        ans -= (s + t);
        s = 0, t = 0;
        tflag = false;
      }
      s++;
      sflag = true;
    } else if (x[i] == 'T' && sflag && s > t) {
      t++;
      tflag = true;
    }
  }
  if (sflag && tflag) ans -= 2 * min(s, t);
  cout << ans << endl;
  return 0;
}
