#include <bits/stdc++.h>
using namespace std;
int main() {
  char s[1100000];
  scanf("%s", s);
  int l = strlen(s);
  int ans = 0;
  int m = 0;
  int p = 0;
  while (s[p] == 'F') p++;
  for (int i = p; i < l; i++) {
    if (s[i] == 'M') {
      m++;
    }
    if (s[i] == 'F') {
      ans = max(ans + 1, m);
    }
  }
  cout << ans << endl;
  return 0;
}
