#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 in;
  cin >> in;
  string S = in, newS;
  do {
    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++;
        }
      }
    }
    newS = "";
    for (int i = 0; i < S.size(); i++)
      if (S[i] != 'N') newS += S[i];
    if (newS == S || S.size() == 0) break;
    S = newS;
  } while (true);
  cout << S.size() << endl;
  return 0;
}
