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