#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  cin >> str;
  int n = 0, pf = -1;
  for (int i = 0; i < str.size(); i++) {
    if (str[i] == 'M') n++;
    if (str[i] == 'F' && n) {
      pf = max(n, pf + 1);
    }
  }
  cout << max(pf, 0);
}
