#include <bits/stdc++.h>
using namespace std;
long long t[1000005], d = 1000005, c = 0;
string a;
int main() {
  cin >> a;
  for (int i = 0; i < a.size(); i++)
    if (a[i] == 'M') {
      d = i;
      break;
    }
  long long prev = 0, s = 0;
  for (int i = d; i < a.size(); i++) {
    if (a[i] == 'M') continue;
    if (s == 0)
      t[i] = i - d;
    else if (i - (d + s) > t[prev])
      t[i] = i - (d + s);
    else
      t[i] = t[prev] + 1;
    s++;
    prev = i;
  }
  cout << t[prev] << endl;
  return 0;
}
