#include <bits/stdc++.h>
using namespace std;
int inf = 2147483647;
const long long ll = 9223372036854775807, ninf = 1000000000;
const double eps = 1e-6;
;
int main() {
  string a;
  while (cin >> a) {
    int now = 0;
    while (a[now] == 'F') now++;
    int m = 0;
    int ans = 0;
    for (int i = now; i < a.size(); i++) {
      if (a[i] == 'M') m++;
      if (a[i] == 'F') {
        ans = max(ans + 1, m);
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
