#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000010;
char v[MAXN];
int main() {
  scanf(" %s", v);
  int n = strlen(v);
  int tleft = 0;
  int p0 = n;
  for (int i = 0; i < (n); ++i)
    if (v[i] == 'M') {
      p0 = i;
      break;
    }
  int tgt = p0;
  for (int i = p0; i < (n); ++i) {
    if (v[i] == 'F') {
      tleft = max(i - tgt, tleft + 1);
      ++tgt;
    }
  }
  printf("%d\n", tleft);
  return 0;
}
