#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int s = 0, t = 0, ans = 0;
  string x;
  cin >> x;
  for (int i = 0; i < x.size(); i++) {
    if (x[i] == 'S') {
      if (i == 0)
        s = 1;
      else if (x[i - 1] != 'S') {
        ans += min(s, t);
        s = 1;
        t = 0;
      } else
        s++;
    }
    if (x[i] == 'T') t++;
  }
  if (t) ans += min(s, t);
  cout << x.size() - ans * 2 << endl;
}
