#include <bits/stdc++.h>
using namespace std;
int test(string s) {
  int n = s.size();
  int ans = 0;
  while (true) {
    bool isFound = false;
    for (int i = 0; i < n; i++) {
      if (s[i] == 'M' && i + 1 < n && s[i + 1] == 'F') {
        swap(s[i], s[i + 1]);
        isFound = true;
        i++;
      }
    }
    if (!isFound) {
      break;
    }
    ans++;
  }
  return ans;
}
int solve(string& s) {
  int n = s.size();
  int ans = 0;
  int boys = 0;
  int boysAfter = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'F') {
      if (ans == 0) {
        ans = boys;
      } else {
        if (boysAfter >= ans) {
          ans = boys;
        } else {
          ans = max(ans + 1, boys);
        }
      }
      boysAfter = 0;
    } else {
      boys++;
      boysAfter++;
    }
  }
  return ans;
}
int main() {
  if (true) {
    string s;
    while (cin >> s) {
      int ans = solve(s);
      cout << ans << endl;
    }
  } else {
    int n = 20;
    string s = "FFFFFFFFFFFFFFFFFFFF";
    for (int i = 0; i < 1 << 20; i++) {
      for (int j = 0; j < n; j++) {
        if (i & (1 << j)) {
          s[j] = 'F';
        } else {
          s[j] = 'M';
        }
      }
      int s1 = test(s);
      int s2 = solve(s);
      if (s1 != s2) {
        cout << s << endl;
        break;
      }
    }
  }
  return 0;
}
