#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int n;
int a[maxn];
int s[maxn];
int ctm[maxn];
string str;
int main() {
  cin >> str;
  n = str.size();
  int h = 0;
  while (str[h] == 'F' && h < n) h++;
  int tail = n - 1;
  while (str[tail] == 'M' && tail >= h) tail--;
  if (tail < h) {
    printf("0\n");
    return 0;
  } else {
    str = str.substr(h, tail - h + 1);
    n = str.size();
  }
  ctm[0] = (str[0] == 'M') ? 1 : 0;
  for (int i = 1; i < n; i++) ctm[i] = ctm[i - 1] + ((str[i] == 'M') ? 1 : 0);
  int ap = 0;
  for (int i = 0; i < n; i++) {
    if (str[i] == 'F') {
      a[ap++] = i;
    }
  }
  s[0] = ctm[a[0]];
  for (int i = 1; i < ap; i++) {
    s[i] = max(ctm[a[i]], s[i - 1] + 1);
  }
  int res = s[0];
  for (int i = 1; i < ap; i++) {
    res = max(res, s[i]);
  }
  printf("%d\n", res);
  return 0;
}
