#include <bits/stdc++.h>
using namespace std;
void check(string val) { cout << val << endl; }
int main(int argc, char** argv) {
  string X;
  cin >> X;
  bool ST_check = false;
  int S_count = 0;
  int T_count = 0;
  int m_count = 0;
  for (int i = 0; i < X.length(); i++) {
    if (X[i] == 'S') {
      if (!ST_check) {
        int num = (S_count <= T_count) ? S_count : T_count;
        m_count += num * 2;
        S_count = 0;
        T_count = 0;
      }
      ST_check = true;
      S_count++;
    }
    if (X[i] == 'T') {
      T_count++;
      ST_check = false;
    }
    if (m_count > 100000) {
      ST_check = true;
      break;
    }
  }
  if (!ST_check) {
    int num = (S_count <= T_count) ? S_count : T_count;
    m_count += num * 2;
  }
  cout << X.length() - m_count << endl;
}
