#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string x;
  cin >> x;
  int n = x.size();
  vector<int> c;
  int t = 1;
  if (x[0] == 'T') c.push_back(0);
  for (int i = 0; i < n - 1; i++) {
    if (x[i] != x[i + 1]) {
      c.push_back(t);
      t = 1;
    } else
      t++;
  }
  c.push_back(t);
  int res = 0;
  for (int i = 0; i < c.size() - 1; i += 2) res += min(c[i], c[i + 1]);
  res = n - 2 * res;
  cout << res << "\n";
  return 0;
}
