#include <bits/stdc++.h>
using namespace std;
long long int n, i, ans, tnt;
string str;
char a[1000005];
int main() {
  cin >> str;
  n = str.length();
  for (i = 0; i < n; i++) {
    a[i + 1] = str[i];
  }
  ans = 0;
  tnt = 0;
  for (i = 1; i <= n; i++) {
    if (a[i] == 'M') {
      tnt++;
    } else if (tnt != 0) {
      ans = max(ans + 1, tnt);
    }
  }
  cout << ans << endl;
}
