#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  string S;
  cin >> S;
  int n = S.size();
  int s = 0, t = 0;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (S[i] == 'T')
      t++;
    else
      s++;
    if (t > s) {
      ans++;
      t = s = 0;
    }
    if (t == s) {
      t = s = 0;
    }
  }
  ans += s;
  cout << ans << endl;
}
