#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
  cin >> s;
  int ssz = s.size();
  int mcnt = 0, fcnt = 0, last = 0;
  for (int i = 0; i < ssz; i++) {
    mcnt += (s[i] == 'M');
    fcnt += (s[i] == 'F');
    if (s[i] == 'M') continue;
    if (mcnt == 0) {
      last = 0;
    } else if (mcnt > 0 && last < i - fcnt + 1) {
      last = mcnt;
    } else {
      last++;
    }
  }
  cout << last << endl;
  return 0;
}
