#include <bits/stdc++.h>
using namespace std;
long long const INF = 1LL << 60;
long long const MAX_N = 510000;
long long const MOD = 1000000007;
int main() {
  string X;
  cin >> X;
  int len = X.length() / 2;
  while (len > 0) {
    string q = "";
    for (int j = 1; j <= len; j++) {
      q += "S";
    }
    for (int j = 1; j <= len; j++) {
      q += "T";
    }
    if (X.find("S") == string::npos || X.find("T") == string::npos) {
      break;
    }
    unsigned long pos = X.find(q);
    if (pos == string::npos) {
      len--;
    } else {
      while (pos != string::npos) {
        X.erase(pos, q.length());
        pos = X.find(q);
      }
      len = X.length() / 2;
    }
  }
  cout << X.length() << endl;
  return 0;
}
