#include <bits/stdc++.h>
using namespace std;
char c[1 << 20];
int main() {
  scanf("%s", c);
  int Max = 0;
  int Time = 0;
  int Cnt = 0;
  for (int i = 0; c[i]; i++) {
    if (c[i] == 'M') {
      Time--;
      if (Time < 0) Time = 0;
    } else {
      Max = max(Max, Time + i - Cnt);
      if (Cnt != i) Time++;
      Cnt++;
    }
  }
  cout << Max << endl;
  return 0;
}
