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