#include <bits/stdc++.h>
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9 + 7;
int main() {
  string S;
  cin >> S;
  vector<int> accum(S.size());
  accum[0] = S[0] == 'S';
  for (int i = 1; i < S.size(); i++) {
    accum[i] = accum[i - 1];
    if (S[i] == 'S') accum[i]++;
  }
  int maxi = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'T') maxi = max(maxi, accum[i]);
  }
  cout << S.size() - maxi * 2 << endl;
}
