#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;
int main() {
  string x;
  cin >> x;
  int s = 0, t = 0;
  for (int i = 0; i < x.length(); i++) {
    if (x.substr(i, 1) == "T") {
      t++;
      if (s > 0) {
        if (t >= s) {
          t -= s;
          s = 0;
        } else {
          s -= t;
          t = 0;
        }
      }
    } else {
      s++;
    }
  }
  cout << s + t << endl;
}
