#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;
const dd PI = 3.1415926435;
ll gcd(ll a, ll b) {
  if (a % b == 0) {
    return b;
  }
  return gcd(b, a % b);
}
ll fact(ll n) {
  if (n == 0) {
    return 1;
  }
  if (n == 1) {
    return 1;
  }
  return n * fact(n - 1) % MOD;
}
ll pow_fast(ll n, ll k) {
  if (k == 0) {
    return 1;
  }
  if (k == 1) {
    return n;
  }
  if (k % 2 == 0) {
    ll tmp = pow_fast(n, k / 2LL);
    return tmp * tmp % MOD;
  } else {
    ll tmp = pow_fast(n, k / 2LL);
    tmp *= tmp;
    tmp %= MOD;
    return tmp * n % MOD;
  }
}
map<ll, ll> sosuu(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i] += 1;
      n /= i;
    }
  }
  if (n != 1) {
    res[n] += 1;
  }
  return res;
}
int main() {
  string X;
  cin >> X;
  ll cur = 0;
  ll sum = 0;
  stack<char> stk;
  while (cur < X.size()) {
    if (X[cur] == 'S') {
      stk.push('S');
      cur += 1;
      continue;
    }
    while (cur < X.size() && X[cur] == 'T') {
      if (!stk.empty()) {
        sum += 2;
        stk.pop();
      }
      cur += 1;
    }
    stk = stack<char>();
  }
  cout << X.size() - sum << endl;
}
