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