#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000")
using namespace std;
template <class T>
void out(map<char, T>& a, string s = "(%3c ->%3d)") {
  for (auto(it) = (a).begin(); (it) != (a).end(); ++(it))
    printf(s.c_str(), it->first, it->second);
  printf("\n");
}
template <class T>
void out(vector<T>& a, string s = "%3d ") {
  int i, n = a.size();
  for ((i) = 0; (i) < (n); (i)++) printf(s.c_str(), a[i]);
  printf("\n");
}
template <class T>
void out(T* a, int n, string s = "%3d ") {
  int i;
  for ((i) = 0; (i) < (n); (i)++) printf(s.c_str(), a[i]);
  printf("\n");
}
long long i, j, N, M, n, m, k, p;
int main() {
  char buf[1000005];
  fgets(buf, 1000005, stdin);
  int n = strlen(buf);
  if (buf[n - 1] == '\n') --n;
  buf[n] = 0;
  vector<int> a(n, 0), w(n, 0);
  string s = buf;
  int dist = 0;
  int isM = 0;
  int lasti = -1;
  int kF = 0;
  int fst = 1;
  for ((i) = 0; (i) < (n); (i)++) {
    if (s[i] == 'M') {
      fst = 0;
      if (!isM) dist = 0;
      isM = 1;
      ++dist;
    }
    if (s[i] == 'F') {
      ++kF;
      if (!fst) {
        if (lasti == -1)
          w[i] = max(1ll, i - kF + 1);
        else
          w[i] = max(w[lasti] + 1ll, i - kF + 1);
      } else
        w[i] = 0;
      isM = 0;
      lasti = i;
    }
  }
  if (lasti != -1)
    cout << w[lasti] << endl;
  else
    cout << 0 << endl;
  return 0;
}
