#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 10;
const int inf = 1e9;
int main() {
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  s = " " + s;
  int i;
  int ans = 0;
  int sum = 0;
  for (i = 1; i < (int)s.size(); i++) {
    if (s[i] == 'M') {
      sum++;
    }
    if (s[i] == 'F' && sum > 0) {
      ans = max(ans + 1, sum);
    }
  }
  cout << ans << endl;
  return 0;
}
