#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  string a;
  cin >> a;
  int n = a.size();
  int ans, last, acc;
  ans = last = acc = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == 'M') continue;
    if (i == acc) {
      acc++;
      continue;
    }
    last = max(last + 1, i - acc);
    ans = max(ans, last);
    acc++;
  }
  cout << ans << endl;
  return 0;
}
