#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
struct Dat {
  char c;
  ll num;
};
int main() {
  string X;
  cin >> X;
  vector<Dat> tbl;
  Dat cur;
  auto create_dat = [&](char in_c) {
    Dat d;
    d.c = in_c;
    d.num = 1;
    tbl.push_back(d);
  };
  for (ll i = 0; i < X.size(); ++i) {
    char ts = X[i];
    if (tbl.size() <= 0 || tbl.back().c != ts) {
      create_dat(ts);
    } else {
      ++tbl.back().num;
    }
  }
  for (ll i = 0; i < tbl.size() - 1; ++i) {
    if (tbl[i].c == 'S' && tbl[i + 1].c == 'T') {
      ll num = min(tbl[i].num, tbl[i + 1].num);
      tbl[i].num -= num;
      tbl[i + 1].num -= num;
    }
  }
  ll ans = 0;
  for (const auto& t : tbl) {
    ans += t.num;
  }
  cout << ans << endl;
  return 0;
}
