#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<LL>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using mll = map<LL, LL>;
using vpi = vector<pi>;
bool is_prime(LL n) {
  for (LL i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
LL gcd(LL a, LL b) {
  LL r;
  while ((r = a % b) != 0) {
    a = b;
    b = r;
  }
  return b;
}
LL lcm(LL a, LL b) { return (a / gcd(a, b) * b); }
LL factorial(LL n) {
  LL a = 1, ret = 1;
  while (a < n) {
    a++;
    ret *= a;
  }
  return ret;
}
signed main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  st x;
  cin >> x;
  LL n = ((LL)x.size());
  sc s, t;
  LL del = 0;
  for (LL i = 0; i < n; i++) {
    if (x[i] == 'S') {
      s.push(x[i]);
    } else {
      t.push(x[i]);
      while (!s.empty() && !t.empty() && s.top() == 'S' && t.top() == 'T') {
        s.pop();
        t.pop();
        del += 2;
      }
    }
  }
  cout << n - del;
  return 0;
}
