#include <bits/stdc++.h>
using namespace std;
char c[1000010];
int q[1000010], sum[1000010];
int pl, su;
int cnt;
bool fg;
long long ans;
int main() {
  char ch = getchar();
  while (ch == 'M' || ch == 'F') {
    fg = (ch == 'M' ? 1 : fg);
    if (fg == 1) c[++cnt] = ch;
    ch = getchar();
  }
  for (int i = 1; i <= cnt; ++i) {
    if (c[i] == 'F') {
      ans = max(ans, 1ll * (pl + su));
      ++pl;
    }
    if (c[i] == 'M') {
      ++su;
      pl == 0 ? pl = 0 : --pl;
    }
  }
  printf("%lld", ans);
  return 0;
}
