#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
inline ostream &operator<<(ostream &os, const pair<A, B> &v) {
  return os << v.first << ' ' << v.second;
}
template <typename A>
inline ostream &operator<<(ostream &os, const vector<A> &v) {
  auto it = v.begin();
  os << *it;
  for (++it; it != v.end(); os << ' ' << *it++)
    ;
  return os;
}
void tr() { cout << '\n'; }
template <typename H, typename... T>
inline void tr(H head, T... tail) {
  cerr << head << ' ';
  tr(tail...);
}
void solve(string &s) {
  int len = s.length();
  vector<int> ans(len, 0);
  int k = 0, t = 0;
  for (int i = 0; i < len; i++) {
    if (s[i] == 'M')
      t = 1;
    else {
      if (t) ans[k] = !k ? i - k : max(ans[k - 1] + 1, i - k);
      k++;
    }
  }
  k > 0 ? cout << ans[k - 1] : cout << 0;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  string s;
  cin >> s;
  solve(s);
  return 0;
}
