#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  std::ios::sync_with_stdio(false);
  string temp;
  cin >> temp;
  int ans = temp.size();
  int tk, bk;
  tk = bk = 0;
  for (int i = 0; i <= (int)temp.size() - 1; i++) {
    if (i >= 1 && temp[i] != temp[i - 1]) {
      if (temp[i - 1] == 'T') {
        ans -= min(tk, bk) * 2;
        tk = bk = 0;
      }
    }
    if (temp[i] == 'T')
      tk++;
    else
      bk++;
  }
  cout << ans - min(tk, bk) * 2 << endl;
  return 0;
}
