#include <bits/stdc++.h>
using namespace std;
int main() {
  string X;
  cin >> X;
  vector<int> L(X.size(), 0), R(X.size(), 0);
  for (int i = 0; i < (int)(X.size() - 1); i++) {
    int l = i, r = i + 1;
    while (0 <= l && r < X.size()) {
      while (X[l] == '-') {
        if (l == 0) break;
        if (L[l] != 0)
          l = L[l] - 1;
        else
          l--;
      }
      while (X[r] == '-') {
        if (r == X.size() - 1) break;
        if (R[r] != 0) {
          r = R[r] + 1;
        } else {
          r++;
        }
      }
      for (int j = l + 1; j <= i; j++) L[j] = l;
      for (int j = r - 1; j > i; j--) R[j] = r;
      if (l < 0 || X.size() <= r) break;
      if (X[l] != 'S' || X[r] != 'T') break;
      X[l] = '-', X[r] = '-';
      l--, r++;
    }
  }
  long long ans = 0;
  for (int i = 0; i < (int)(X.size()); i++) {
    if (X[i] == 'S' || X[i] == 'T') ans++;
  }
  cout << ans << endl;
}
