#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int ans = 0, len = s.length();
  int s_stack = 0;
  for (int i = 0; i < len - 1; ++i) {
    cerr << s[i] << " " << s_stack << endl;
    if (s[i] == 'S') {
      if (s[i + 1] == 'T') {
        ans++;
        i++;
      } else {
        s_stack++;
      }
    } else if (s_stack) {
      ans++;
      s_stack--;
    }
  }
  cout << len - 2 * ans << endl;
  return 0;
}
