#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  string x;
  cin >> x;
  int n = x.size();
  x.push_back('A');
  int cons = 0;
  int cont = 0;
  int res = n;
  for (long long i = 0; i < (long long)(n + 1); i++) {
    if (x[i] == 'S') {
      if (cont > 0) {
        res -= min(cons, cont) * 2;
        cons = 0;
        cont = 0;
      }
      cons++;
    } else if (x[i] == 'T') {
      if (cons > 0) {
        cont++;
      }
    } else {
      res -= min(cons, cont) * 2;
      cons = 0;
      cont = 0;
    }
  }
  cout << res << "\n";
  return 0;
}
