#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = 1001001001;
int main() {
  string s;
  cin >> s;
  int n = s.size();
  int ans = n;
  int counts = 0, countt = 0;
  if (s[0] == 'S')
    counts++;
  else
    countt++;
  for (int i = 1; i < n; ++i) {
    if (s[i] == 'S') {
      if (s[i - 1] == 'T') {
        ans -= 2 * min(counts, countt);
        counts = 1;
        countt = 0;
      } else
        counts++;
    }
    if (s[i] == 'T') {
      countt++;
    }
  }
  if (countt > 0) ans -= 2 * min(counts, countt);
  cout << ans << endl;
}
