#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int m, f;
  m = f = 0;
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'M')
      m++;
    else if (m)
      f = max(f + 1, m);
  }
  cout << f;
  return 0;
}
