#include <bits/stdc++.h>
using namespace std;
const double pi = 3.1415926535897932384626433832;
const long long mod = 1e9 + 7;
complex<double> fast_exp(complex<double> a, long long b) {
  if (b == 0) return 1;
  complex<double> res = fast_exp(a, b / 2);
  res = res * res;
  if (b % 2 == 1) res = res * a;
  return res;
}
long long fastexpon(long long a, long long b, long long mod) {
  if (b == 0) return 1;
  long long res = fastexpon(a, b / 2, mod);
  res = (res * res) % mod;
  if (b % 2 == 1) res = (res * a) % mod;
  return res;
}
struct custom {
  bool operator()(long long a, long long b) { return a > b; }
};
int dp[(int)1e6 + 5] = {};
int main() {
  string s;
  cin >> s;
  int cur = 0;
  vector<int> reservoir;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'M')
      cur++;
    else {
      reservoir.push_back(cur);
      cur = 0;
    }
  }
  int need_moves = 0;
  int len = reservoir.size();
  if (len == 0) {
    cout << 0 << endl;
    return 0;
  }
  dp[len - 1] = reservoir[len - 1];
  for (int i = len - 2; i >= 0; i--) {
    if (reservoir[i] > 0) {
      dp[i] = max(dp[i + 1], len - 1 - i) + reservoir[i];
    } else
      dp[i] = dp[i + 1];
  }
  cout << dp[0] << endl;
  return 0;
}
