#include <bits/stdc++.h>
using namespace std;
char s[1000005];
int d[1000005];
int main() {
  scanf("%s", s);
  int len = strlen(s);
  int tmp = 0, tt = 0;
  for (int i = 0; i < len; i++) {
    if (s[i] == 'M') {
      tt++;
    } else {
      if (tmp == 0)
        d[tmp] = i;
      else {
        if (tt == 0)
          d[tmp] = 0;
        else
          d[tmp] = max(d[tmp - 1] + 1, tt);
      }
      tmp++;
    }
  }
  printf("%d\n", d[tmp - 1]);
  return 0;
}
