#include <bits/stdc++.h>
using namespace std;
signed main() {
  string a;
  long long s, ans = 0;
  cin >> a;
  long long n = a.size();
  for (long long i = 0; i < (n); ++i) {
    if (a[i] == 'S') s++;
    if (s != 0 && a[i] == 'T') {
      ans++;
      s--;
    }
  }
  cout << ans;
  return 0;
}
