#include <bits/stdc++.h>
using namespace std;
pair<int, int> B[1000 * 1000 + 10];
int A[1000 * 1000 + 10], plc[1000 * 1000 + 10];
int main() {
  string s;
  cin >> s;
  int n = s.size();
  for (int i = 0; i < n; i++) {
    char c = s[i];
    if (c == 'M') A[i] = 1;
    B[i] = pair<int, int>(A[i], i);
  }
  sort(B, B + n);
  for (int i = 0; i < n; i++) plc[B[i].second] = i;
  int p = 0;
  for (int i = 0; i < n; i++) {
    if (A[i] || plc[i] == i) continue;
    p = max(p + 1, i - plc[i]);
  }
  cout << p << endl;
  return 0;
}
