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