#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int i = 0, bad = 0, len = s.size();
  while (i < len) {
    while (s[i] == 'T') {
      ++i;
      ++bad;
    }
    if (s[i] == 'S') {
      int bal = 0, slen = 0;
      while (i < len) {
        ++slen;
        if (s[i] == 'S')
          ++bal;
        else
          --bal;
        ++i;
        if (bal == 0) break;
      }
      if (bal != 0) bad += slen;
    }
  }
  cout << bad << '\n';
  return 0;
}
