#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  vector<long long> a;
  long long k = 1;
  int n = (int)(s).size();
  for (int i = (1); i < ((int)(s).size()); ++i) {
    if (s[i] == s[i - 1]) {
      k++;
    } else {
      if (s[i] == 'T') {
        a.push_back(k);
      } else {
        a.push_back(-k);
      }
      k = 1;
    }
  }
  if (s[n - 1] == 'T') {
    a.push_back(-k);
  } else {
    a.push_back(k);
  }
  for (int i = (0); i < ((int)(a).size() - 1); ++i) {
    if (a[i] > 0) {
      int x = a[i];
      int y = -a[i + 1];
      a[i] -= min(x, y);
      a[i + 1] += min(x, y);
    }
  }
  long long ret = 0;
  for (int i = (0); i < ((int)(a).size()); ++i) {
    ret += abs(a[i]);
  }
  cout << ret << endl;
  return 0;
}
