#include <bits/stdc++.h>
using namespace std;
int main() {
  int mod = 0, s = 0, t = 0, st = 0;
  string word;
  cin >> word;
  for (int i = 0; i < word.size(); i++) {
    if (word[i] == 'S') {
      if (mod == 1) {
        st += 2 * min(t, s);
        mod = 0;
      }
      s += 1;
      t = 0;
    }
    if (word[i] == 'T') {
      t += 1;
      mod = 1;
    }
  }
  cout << word.size() - st;
}
