#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
int main() {
  string x;
  cin >> x;
  int s = 0;
  char prev = 'T';
  int del = 0;
  for (int i = 0; i < x.length(); i++) {
    if (x[i] == 'T') {
      if (s > 0) {
        s--;
        del += 2;
      }
    } else {
      if (prev == 'T') {
        s = 1;
      } else {
        s++;
      }
    }
    prev = x[i];
  }
  cout << x.length() - del << endl;
  return 0;
}
