#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int n = s.size();
  vector<int> A(n, 0);
  for (int i = 0; i < n; i++) {
    if (s[i] == 'S') A[i]++;
    if (i > 0) A[i] += A[i - 1];
  }
  int sc = 1, rc = 0;
  for (int i = 1; i < n; i++) {
    if (s[i] == 'T') {
      A[i] -= sc;
      sc++;
      if (A[i] >= 0) rc++;
    }
  }
  cout << n - rc * 2 << endl;
  return 0;
}
