#include <bits/stdc++.h>
using namespace std;
int main() {
  string X;
  cin >> X;
  long long n = X.size();
  bool flagS = false, flagT = false;
  long long countS = 0, countT = 0;
  long long sumDelete = 0;
  for (int(i) = 0; (i) < (n); ++(i)) {
    if (X[i] == 'S') {
      if (flagS) {
        countS++;
      } else {
        flagS = true;
        if (flagT) {
          flagT = false;
          sumDelete += 2 * min(countS, countT);
        }
        countS = 1;
        countT = 0;
      }
    } else if (X[i] == 'T') {
      if (flagT) {
        countT++;
      } else {
        flagT = true;
        flagS = false;
        countT = 1;
      }
    }
  }
  sumDelete += 2 * min(countS, countT);
  long long ans = n - sumDelete;
  cout << ans << endl;
}
