#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int N = S.size();
  int s_end = 0, t_begin = 0;
  while (S[t_begin] == 'T') {
    t_begin++;
  }
  while (S[N - 1 - s_end] == 'S') {
    s_end++;
  }
  cout << t_begin + s_end + max(N / 2 - t_begin, N / 2 - s_end) -
              min(N / 2 - t_begin, N / 2 - s_end)
       << endl;
}
