#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int inf = 2e9 + 5;
double PI = 3.14159265358979323846;
void solve() {
  string s;
  cin >> s;
  int n = (int)s.length();
  int male = 0;
  int female = 0;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'M') {
      male++;
      if (female > 0) female--;
    } else {
      if (male) {
        ans = max(ans, male + female);
        female++;
      }
    }
  }
  cout << ans << "\n";
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
