#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = (int)(s).size();
  int p = (s[0] == 'S');
  int q = 0;
  int ans = 0;
  for (int i = 1; i < n; ++i) {
    if (s[i] == 'S') {
      if (s[i - 1] == 'T') p = 0;
      p++;
    } else if (p > 0) {
      ans += 2;
      p--;
    }
  }
  cout << n - ans << endl;
  return 0;
}
