#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int m, n, ans;
char s[N];
int main() {
  scanf("%s", s + 1), n = strlen(s + 1);
  for (int i = 1; i <= n; ++i) {
    if (s[i] == 'M')
      ++m;
    else if (m > 0)
      ans = max(ans + 1, m);
  }
  return 0 & printf("%d", ans);
}
