#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int res = 0;
  int ms = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'F' && ms == 0)
      continue;
    else if (s[i] == 'M') {
      ms++;
      continue;
    }
    if (s[i] == 'F') {
      if (i != 0 && s[i - 1] == 'F')
        res++;
      else if ((ms - res) > 0)
        res += (ms - res);
      else
        res++;
    }
  }
  cout << res << endl;
}
