#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
string X;
void solve() {
  int i = 0;
  int ans = X.size();
  while (i < X.size()) {
    int c_s = 0, c_t = 0;
    bool prev_s = false;
    while (X[i] == 'S') {
      c_s++;
      i++;
      prev_s = true;
    }
    while (X[i] == 'T') {
      i++;
      if (prev_s) {
        c_t++;
      }
    }
    ans -= 2 * min(c_s, c_t);
  }
  cout << ans << endl;
}
int main() {
  cin >> X;
  solve();
  return 0;
}
