#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
int main() {
  string s;
  cin >> s;
  int ans = 0;
  int f = 0, m = 0;
  for (int i = (0); i < (int((s).size())); ++i)
    if (s[i] == 'M')
      m++;
    else {
      if (m > 0) f = max(m, f + 1);
      ans = max(ans, f);
    }
  cout << ans;
  return 0;
}
