#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string x;
  cin >> x;
  int n = x.size();
  int ss = 0;
  bool ts = true;
  for (int i = 0; i < (int)x.size(); ++i) {
    if (ts && x[i] == 'S')
      ss++;
    else if (ts && x[i] == 'T') {
      if (ss != 0) {
        ss--;
        n -= 2;
      }
      ts = false;
    } else if (!ts && x[i] == 'T') {
      if (ss != 0) {
        ss--;
        n -= 2;
      }
    } else {
      ts = true;
      ss = 1;
    }
  }
  cout << n << "\n";
  return 0;
}
