#include <bits/stdc++.h>
using namespace std;
int main() {
  int mod = 0, s = 0, t = 0, st = 0, j = 0;
  string word;
  cin >> word;
  while (j < word.size()) {
    for (j; word[j] == 'S'; j++) {
      s += 1;
    }
    for (j; word[j] == 'T'; j++) {
      t += 1;
    }
    st += 2 * min(s, t);
    s = 0;
    t = 0;
  }
  cout << word.size() - st;
}
