#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
const int MOD = 1000000007;
const int INF = 1 << 30;
int main() {
  string x;
  cin >> x;
  int n = x.size();
  int res = n;
  int s = 0, t = 0;
  if (x[0] == 'S')
    s++;
  else
    t++;
  for (int i = 1; i < n; i++) {
    if (x[i] == 'S' && x[i - 1] == 'T') {
      res -= 2 * min(s, t);
      s = 1;
      t = 0;
    } else if (x[i] == 'S') {
      s++;
    } else if (x[i] == 'T') {
      t++;
    }
  }
  if (t > 0) {
    res -= 2 * min(s, t);
  }
  cout << res << endl;
  return 0;
}
