#include <bits/stdc++.h>
using namespace std;
int main() {
  string x;
  cin >> x;
  vector<int> cnt;
  cnt.push_back(1);
  for (int i = 1; i < x.length(); i++) {
    if (x[i] == x[i - 1])
      cnt.at(cnt.size() - 1)++;
    else {
      cnt.push_back(1);
    }
  }
  int ans = x.length();
  int s = 1;
  if (x[0] == 'T') s = 2;
  for (; s < cnt.size(); s += 2) {
    ans -= 2 * min(cnt.at(s - 1), cnt.at(s));
  }
  cout << ans << endl;
  return 0;
}
