#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  string s;
  cin >> s;
  vector<long long int> ans;
  long long int c = 0;
  long long int j = 0;
  for (long long int i = 0; i < s.size(); i++) {
    if (s[i] == 'F') {
      j++;
    } else
      break;
  }
  for (long long int i = j; i < s.size(); i++) {
    if (s[i] == 'M')
      c++;
    else
      ans.push_back(c);
  }
  for (long long int i = 1; i < ans.size(); i++) {
    if (ans[i] <= ans[i - 1]) ans[i] = ans[i - 1] + 1;
  }
  if (ans.size() == 0)
    cout << 0;
  else
    cout << ans[ans.size() - 1];
}
