#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int cs = 0, ct = 0;
  int dc = 0;
  for (int i = 0; i < (int)s.size(); ++i) {
    char c = s[i];
    if (i == (int)s.size() - 1) {
      if (c == 'T') {
        dc += min(ct + 1, cs);
      } else {
        if (ct > 0) {
          dc += min(ct, cs);
        }
      }
      break;
    }
    if (c == 'T') {
      if (cs > 0) {
        ++ct;
      }
    } else {
      if (ct > 0) {
        dc += min(cs, ct);
        ct = 0;
        cs = 1;
      } else {
        ++cs;
      }
    }
  }
  cout << (int)s.size() - 2 * dc;
  return 0;
}
