#include <bits/stdc++.h>
using namespace std;
int main() {
  string X;
  cin >> X;
  int cntLeftT = 0, cntRightS = 0;
  int indexS, indexE;
  for (int i = 0; i < X.length(); i++) {
    if (X[i] == 'S') {
      indexS = i;
      break;
    } else if (X[i] == 'T')
      cntLeftT++;
  }
  for (int i = X.length() - 1; i >= 0; i--) {
    if (X[i] == 'S')
      cntRightS++;
    else if (X[i] == 'T') {
      indexE = i;
      break;
    }
  }
  if (indexE < indexS) {
    cout << X.length() << endl;
    return 0;
  }
  int cntS = 0, cntT = 0;
  int ans = cntLeftT + cntRightS;
  for (int i = indexS; i <= indexE; i++) {
    if (X[i] == 'S') {
      cntS++;
      if (i + 1 == indexE) {
        cntT++;
        ans += abs(cntS - cntT);
        break;
      }
    } else if (X[i] == 'T') {
      cntT++;
      if (i + 1 == indexE) {
        cntT++;
        ans += abs(cntT - cntS);
        break;
      } else if (X[i + 1] == 'S') {
        ans += abs(cntT - cntS);
        cntT = 0, cntS = 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
