#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
char a[maxn];
int main() {
  scanf("%s", a + 1);
  int len = strlen(a + 1);
  int ans = 0, num = 0;
  for (int i = 1; i <= len; i++) {
    if (a[i] == 'M') {
      num++;
      continue;
    }
    if (a[i] == 'F' && num != 0) ans = max(ans + 1, num);
  }
  printf("%d\n", ans);
  return 0;
}
