#include <bits/stdc++.h>
char s[(int)1e6 + 11];
int main() {
  gets(s);
  int z = 0, a = 0;
  char* c = s;
  while (*c)
    if (*c++ == 'M')
      ++z;
    else if (z)
      a = std::max(z, a + 1);
  std::cout << a;
  return 0;
}
