#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
char data[maxn];
int main() {
  scanf("%s", &data);
  int idx = 0;
  int ans = 0;
  int cntt = 0;
  int flag = 0;
  while (data[idx] == 'F' && idx < strlen(data)) {
    idx += 1;
    flag = 1;
  };
  ans = 0;
  for (int i = idx; i < strlen(data); i++) {
    if (data[i] == 'M') {
      cntt += 1;
      flag = 1;
    } else {
      ans = max(ans + 1, cntt);
    }
  }
  cout << ans << endl;
  return 0;
}
