#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int now = s.size();
  for (int i = 0; i < (s.size()); i++) {
    if (s[i] == 'S') {
      now = i;
      break;
    }
  }
  if (now == s.size()) {
    cout << s.size() << endl;
    return 0;
  }
  vector<int> cnts, cntt;
  for (int i = now; i < s.size(); i++) {
    if (s[i] == 'S') {
      int cnt = 0;
      while (s[i] == 'S') {
        cnt++;
        i++;
      }
      cnts.push_back(cnt);
      i--;
    } else {
      int cnt = 0;
      while (s[i] == 'T') {
        cnt++;
        i++;
      }
      cntt.push_back(cnt);
      i--;
    }
  }
  int cnt = 0;
  if (cnts.size() > cntt.size()) {
    cntt.push_back(0);
  }
  for (int i = 0; i < (cnts.size()); i++) {
    cnt += min(cnts[i], cntt[i]);
  }
  cout << s.size() - 2 * cnt << endl;
}
