#include <bits/stdc++.h>
using namespace std;
void solve(string& str) {
  int ab = 0;
  if ((ab = str.find("ST") == -1)) return;
  int pos = 0;
  int s = 0;
  int t = 0;
  int p1 = 0;
  int p2 = 0;
  int m = 0;
  int len = str.length();
  while (m < len) {
    bool ju = false;
    if (m < len && str.at(pos) == 'S') {
      ju = true;
      p1 = pos;
      pos++;
      m++;
      s++;
    }
    if (ju && m < len && str.at(pos) == 'T') {
      p2 = pos;
      pos++;
      m++;
      t++;
    }
    if (t == s) {
      str.erase(p1 - s + 1, 2 * s);
      pos -= 2 * s;
    } else if (s > t) {
      str.erase(p1 - t + 1, 2 * t);
      pos -= 2 * t;
    } else {
      str.erase(p1 - s + 1, 2 * s);
      pos -= 2 * s;
    }
    s = 0;
    t = 0;
    if (!ju) {
      pos++;
      m++;
    }
  }
  solve(str);
}
int main() {
  string str;
  cin >> str;
  solve(str);
  cout << str.length();
}
