#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
char s[1000007];
int main() {
  scanf("%s", s);
  int ans = 0, k = 0, flag = 0;
  for (int i = 0; i <= strlen(s) - 1; i++) {
    if (!flag && s[i] == 'F') continue;
    if (s[i] == 'M')
      k++, flag = 1;
    else
      ans = max(ans + 1, k);
  }
  printf("%d\n", ans);
}
