#include <bits/stdc++.h>
using namespace std;
const int64_t INF = 1e18 + 1;
const int64_t N = 300500;
const int64_t mod = 1000000007;
int64_t fact[N];
int64_t invFact[N];
void _init_() {
  fact[0] = invFact[0] = 1;
  for (int64_t i = 1; i < N; i++) {
    fact[i] = (fact[i - 1] * i) % mod;
  }
  int64_t i = N - 1;
  invFact[i] = pow(fact[i], mod - 2);
  for (i--; i >= 0; i--) {
    invFact[i] = (invFact[i + 1] * (i + 1)) % mod;
  }
}
int64_t C(int64_t n, int64_t k) {
  if (k > n) {
    return 0;
  }
  return fact[n] * invFact[k] % mod * invFact[n - k] % mod;
}
bool comp(pair<int64_t, int64_t> p1, pair<int64_t, int64_t> p2) {
  if (p1.first < p2.first)
    return true;
  else if (p1.second > p2.second)
    return true;
  return false;
}
void solve(int64_t cnt) {
  string s;
  cin >> s;
  int64_t ans = 0;
  int64_t len = s.length();
  int64_t pos = 0, pre = 0;
  while (pos < len and s[pos] == 'F') pos++;
  for (int64_t i = pos; i < len; i++) {
    if (s[i] == 'M')
      pre++;
    else
      ans = max(ans + 1, pre);
  }
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int64_t t = 1;
  int64_t cnt = 1;
  while (t--) {
    solve(cnt);
    cnt++;
  }
}
