#include <bits/stdc++.h>
using namespace std;
void MAIN() {
  string s;
  cin >> s;
  long long n = s.size();
  vector<long long> l(n), r(n);
  for (long long i = 0; i < n; i++) {
    if (s[i] == 'S') {
      l[i]++;
      if (i) l[i] += l[i - 1];
    }
  }
  for (long long i = n - 1; i >= 0; i--) {
    if (s[i] == 'T') {
      r[i]++;
      if (i != n - 1) r[i] += r[i + 1];
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n - 1; i++) {
    if (s.substr(i, 2) == "ST") {
      ans += min(l[i], r[i + 1]);
    }
  }
  cout << n - ans * 2 << '\n';
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long T = 1;
  while (T--) MAIN();
}
