#include <bits/stdc++.h>
using namespace std;
const int Nn = 1e6 + 5;
int N, Man = 0, Ans = 0;
char S[Nn];
int main() {
  scanf("%s", S + 1);
  N = strlen(S + 1);
  for (int i = 1; i <= N; i++) {
    if (S[i] == 'M')
      Man++;
    else if (Man) {
      Ans = max(Ans + 1, Man);
    }
  }
  printf("%d\n", Ans);
  return 0;
}
