#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int N = S.size();
  long ans = 0;
  for (int i = 0; i < N - 1; i++) {
    string s = S.substr(i, 2);
    if (s == "ST") {
      int idx = i, jdx = i + 1;
      while (idx >= 0 && S[idx] == 'S' && S[jdx] == 'T' && jdx < N) {
        idx--;
        jdx++;
      }
      ans += i - idx;
    }
  }
  cout << N - ans * 2 << endl;
}
