#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int dc = 0;
  int cur = 0;
  for (char c : s) {
    if (c == 'T') {
      --cur;
    } else {
      ++cur;
    }
    if (cur >= 0) {
      ++dc;
    }
  }
  cout << (int)s.size() - dc;
  return 0;
}
