#include <bits/stdc++.h>
using namespace std;
long long const INF = 1LL << 60;
int main() {
  string X;
  cin >> X;
  vector<pair<long long, long long>> delete_pairs;
  for (int i = 0; i < X.length(); i++) {
    if (X[i] == 'S') {
      long long s_start = i;
      long long s_end = i;
      while (s_end + 1 < X.length() && X[s_end + 1] == 'S') {
        s_end++;
      }
      long long t_start = s_end + 1;
      long long t_end = s_end + 1;
      while (t_end + 1 < X.length() && X[t_end + 1] == 'T') {
        t_end++;
      }
      if (t_end == s_end + 1) continue;
      if (t_end - t_start < s_end - s_start) {
        long long res = (s_end - s_start) - (t_end - t_start);
        delete_pairs.push_back({s_start + res, t_end});
      } else {
        long long res = (t_end - t_start) - (s_end - s_start);
        delete_pairs.push_back({s_start, t_end - res});
      }
      i = t_end;
    }
  }
  for (auto p : delete_pairs) {
    X = X.substr(0, p.first) +
        X.substr(p.second + 1, (X.length() - 1 - p.second));
  }
  long long ans = X.length();
  for (int i = 0; i < X.length() - 1; i++) {
    if (X[i] == 'S' && X[i + 1] == 'T') {
      ans -= 2;
    }
  }
  cout << ans << endl;
  return 0;
}
