#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll infl = 10000000000000000LL;
constexpr int inf = 1000000000;
int main() {
  string s;
  cin >> s;
  int cnt = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'S') {
      int c[2] = {};
      char t[] = {'S', 'T'};
      int j = i;
      for (int k = 0; k <= 1; ++k) {
        for (; j < s.size(); ++j) {
          if (s[j] != t[k]) break;
          ++c[k];
        }
      }
      cnt += min(c[0], c[1]);
      i = j - 1;
    }
  }
  cout << (s.size() - cnt * 2) << endl;
  return 0;
}
