#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
  cin >> s;
  if (s == "ST") {
    cout << '0' << endl;
    return 0;
  }
  while (1) {
    int len = s.length();
    for (int i = 0; i < s.length() - 2; i++) {
      if (s[i] == 'S') {
        if (s.substr(i, 2) == "ST") {
          s.erase(i, 2);
        }
      }
    }
    if (s[s.length() - 1] == 'T' && s[s.length() - 2] == 'S') {
      int ans = s.length() - 2;
      cout << ans << endl;
      return 0;
    }
    if (len == s.length()) break;
  }
  cout << s.length() << endl;
  return 0;
}
