#include <bits/stdc++.h>
using namespace std;
string s;
long cnt;
long ans;
int main() {
  cin >> s;
  long len = s.length() - 1;
  for (long i = 0; i <= len; i++) {
    if (s[i] == 'M') {
      cnt++;
    } else if (s[i] == 'F' && cnt > 0) {
      ans = max(cnt, ans + 1);
    }
  }
  cout << ans;
  return 0;
}
