#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  int counter = 0;
  int tmp = 0;
  cin >> S;
  for (int i = 0; i < (int)S.length(); i++) {
    if (S[i] == 'T') {
      if (tmp == 0) {
        counter++;
        if (counter == (int)(S.length() / 2)) break;
      } else {
        tmp--;
      }
    } else {
      tmp++;
    }
  }
  if (tmp != counter) cout << "ERROR" << endl;
  cout << counter * 2 << endl;
  return 0;
}
