#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  vector<int> idxs;
  idxs.push_back(0);
  int n = s.size();
  for (int i = 1; i < n; ++i) {
    if (s[i - 1] != s[i]) {
      idxs.push_back(i);
    }
  }
  idxs.push_back(n);
  int dc = 0;
  int st = (s[0] == 'T') ? 1 : 0;
  for (int i = st; i < (int)idxs.size() - 2; i += 2) {
    dc += min(idxs[i + 1] - idxs[i], idxs[i + 2] - idxs[i + 1]);
  }
  cout << (int)s.size() - 2 * dc;
  return 0;
}
