#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string X;
  cin >> X;
  int N = X.size();
  int l = -1, ans = N;
  vector<bool> del(N, false);
  for (int i = 0; i < N; i++) {
    if (X[i] == 'S') {
      l = i;
    } else {
      if (l > -1) {
        ans -= 2;
        del[i] = true;
        del[l] = true;
        while (true) {
          if (del[l])
            l--;
          else
            break;
          if (l < 0) break;
          if (X[l] == 'T') {
            l = -1;
            break;
          }
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
