#include <bits/stdc++.h>
using namespace std;
int main() {
  string x;
  cin >> x;
  if (x.size() == 2) {
    if (x == "ST")
      cout << 0 << endl;
    else
      cout << 2 << endl;
  }
  stack<char> stk;
  char ch;
  for (int i = 0; i < x.size(); i++) {
    ch = x[i];
    if (stk.empty())
      stk.push(ch);
    else {
      if (stk.top() == 'S' && ch == 'T')
        stk.pop();
      else
        stk.push(ch);
    }
  }
  cout << stk.size() << endl;
}
