#include <bits/stdc++.h>
using namespace std;
int main() {
  string X;
  cin >> X;
  int scnt = 0;
  int tcnt = 0;
  int cur = 0;
  int res = 0;
  while (cur < X.size()) {
    while (cur < X.size() && X[cur] == 'S') {
      ++cur;
      ++scnt;
    }
    while (cur < X.size() && X[cur] == 'T') {
      ++cur;
      ++tcnt;
    }
    res += min(scnt, tcnt);
    scnt = 0;
    tcnt = 0;
  }
  cout << X.size() - 2 * res << endl;
}
