#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  while (S.find("ST") != S.npos) {
    size_t pos = 0;
    while ((pos = S.find("ST", pos)) != S.npos) {
      S.replace(pos, 2, "");
      pos++;
    }
  }
  for (int x = 0; x < 200000; x++) {
    for (int i = 0; i < S.length(); i++) {
      if (S[i] == 'S') {
        for (int j = i + 1; j < S.length(); j++) {
          if (S[j] == 'T') {
            int k = j + 1;
            for (; k < S.length(); k++) {
              if (S[k] == 'S') break;
            }
            int sc = j - i;
            int tc = k - j;
            int len = k - i;
            if (sc == tc) {
              S.replace(i, len, "");
            } else if (sc > tc) {
              string ss(sc - tc, 'S');
              S.replace(i, len, ss);
            } else {
              string ss(tc - sc, 'T');
              S.replace(i, len, ss);
            }
            goto EE;
          }
        }
      }
    }
    break;
  EE:;
  }
  cout << S.length() << endl;
}
