#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
int main(void) {
  string S;
  cin >> S;
  int ans = S.size();
  for (int i = 0; i < S.size() - 1; i++) {
    if (S[i] == 'S' && S[i + 1] == 'T') {
      int j = 0;
      while (S[i - j] == 'S' && S[i + j + 1] == 'T' && i - j >= 0 &&
             i + j + 1 < S.size()) {
        S[i - j] = 'N';
        S[i + j + 1] = 'N';
        j++;
      }
      ans -= 2 * j;
    }
  }
  cout << ans << endl;
  return 0;
}
