#include <bits/stdc++.h>
using namespace std;
char s[1000006];
int main() {
  scanf("%s", s + 1);
  int ans = 0;
  int final_pos = 1;
  for (int i = 1; s[i]; i++) {
    if (s[i] == 'M') continue;
    if (i != final_pos) ans = max(ans + 1, i - final_pos);
    final_pos++;
  }
  cout << ans;
  return 0;
}
