#include <bits/stdc++.h>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
void OutputError(std::string s) {
  cerr << "\033[93m" << s << "\033[m" << endl;
  return;
}
int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::string x;
  int64_t result = 0;
  cin >> x;
  result = x.size();
  for (int i = 0; i < x.size();) {
    if (x[i] == 'S') {
      int s_count = 0;
      while (i < x.size() && x[i] == 'S') {
        i++;
        s_count++;
      }
      int t_count = 0;
      while (i < x.size() && x[i] == 'T') {
        i++;
        t_count++;
      }
      result -= std::min(s_count, t_count) * 2;
    } else {
      i++;
    }
  }
  cout << result << endl;
  return 0;
}
