#include <bits/stdc++.h>
using namespace std;
string s;
int del, pos;
int last = -1;
int main() {
  cin >> s;
  int n = s.size();
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'F') {
      if (s[i - 1] == 'F' && i - pos != 0) del++;
      if (i - last) ans = max(i - pos + del, ans);
      pos++;
    }
    if (s[i] == 'M' && s[i - 1] == 'M') del = max(0, del - 1);
  }
  cout << ans << endl;
}
