#include <bits/stdc++.h>
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int vx[4] = {0, 1, 0, -1}, vy[4] = {1, 0, -1, 0};
using namespace std;
int main() {
  string X;
  cin >> X;
  int ans = X.size(), cnt = 1;
  while (X.at(0) == 'T') X.erase(0, 1);
  vector<int> L;
  for (int i = 0; i < X.size(); ++i) {
    if (i == X.size() - 1) {
      L.emplace_back(cnt);
      break;
    }
    if (X.at(i) != X.at(i + 1)) {
      L.emplace_back(cnt);
      cnt = 1;
    } else
      cnt++;
  }
  cnt = 0;
  for (int i = 0; i < L.size() / 2; ++i) {
    cnt += min(L.at(2 * i), L.at(2 * i + 1));
  }
  cout << ans - 2 * cnt << '\n';
  return 0;
}
