#include <bits/stdc++.h>
using namespace std;
char str[1000006];
int main() {
  scanf("%s", str);
  int l = strlen(str);
  int zero = 0, ones = 0;
  int i = l - 1, ans = 0, j;
  while (i >= 0 && str[i] == 'M') i--, l--;
  for (; i >= 0;) {
    if (str[i] == 'F') {
      i--;
      continue;
    }
    ones++;
    ans = max(l - i - ones, ans + 1);
    j = i - 1;
    while (j >= 0 && str[j] == 'M') ones++, ans++, j--;
    i = j;
  }
  printf("%d\n", ans);
  return 0;
}
