#include <bits/stdc++.h>
using namespace std;
const int bfsz = 1 << 16;
char bf[bfsz + 5];
int rsz = 0;
int ptr = 0;
char gc() {
  if (rsz <= 0) {
    ptr = 0;
    rsz = fread(bf, 1, bfsz, stdin);
    if (rsz <= 0) return EOF;
  }
  --rsz;
  return bf[ptr++];
}
void ga(char &c) {
  c = EOF;
  while (!isalpha(c)) c = gc();
}
int gs(char s[]) {
  int l = 0;
  char c = gc();
  while (isspace(c)) c = gc();
  while (c != EOF && !isspace(c)) {
    s[l++] = c;
    c = gc();
  }
  s[l] = '\0';
  return l;
}
template <class T>
bool gi(T &v) {
  v = 0;
  char c = gc();
  while (c != EOF && c != '-' && !isdigit(c)) c = gc();
  if (c == EOF) return false;
  bool neg = c == '-';
  if (neg) c = gc();
  while (isdigit(c)) {
    v = v * 10 + c - '0';
    c = gc();
  }
  if (neg) v = -v;
  return true;
}
long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }
inline int toInt(char xx) { return xx - '0'; }
int exitInput = 0;
int ntest = 1, itest = 1;
void read();
void solve();
int main() {
  ios_base::sync_with_stdio(0);
  for (itest = 1; itest <= ntest; ++itest) {
    read();
    if (exitInput) {
      break;
    }
    if (itest > 1) {
    }
    solve();
  }
  return 0;
}
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const long long Mod = 1e9 + 7;
const int maxn = 1e6 + 3;
const char M = 'M', F = 'F';
int n, m[maxn], nm, ans[maxn];
string s;
int brute() {
  int stop = 0, cnt = 0;
  while (!stop) {
    cnt++;
    stop = 1;
    int i;
    for (i = 0; i < n;) {
      if (i + 1 < n && s[i] == M && s[i + 1] == F) {
        swap(s[i], s[i + 1]);
        stop = 0;
        i += 2;
      } else {
        i++;
      }
    }
  }
  return cnt - 1;
}
void read() {
  cin >> s;
  n = s.size();
}
void solve() {
  int i, j, d;
  for (i = n - 1; i >= 0; i--) {
    if (s[i] == M) {
      if (nm == 0) {
        ans[0] = (n - 1) - i;
      }
      m[nm++] = (n - 1 - i);
    }
  }
  for (i = 1; i < nm; ++i) {
    d = m[i] - i - 1;
    if (ans[i - 1] == 0 || d > ans[i - 1]) {
      ans[i] = m[i] - i;
    } else {
      ans[i] = ans[i - 1] + 1;
    }
  }
  cout << ans[nm - 1] << endl;
}
