#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
int main() {
  string x;
  cin >> x;
  ll temp = 0;
  ll ans = 0;
  ll i = 0;
  ll cnt = 0;
  while (i <= 300030) {
    temp = 0;
    cnt++;
    if (cnt >= 300030) break;
    while (i < x.size() && x[i] == 'S') {
      temp++;
      i++;
    }
    while (i < x.size() && x[i] == 'T' && temp) {
      temp--;
      i++;
      ans++;
    }
  }
  ll n = x.size();
  cout << n - 2 * ans << endl;
  return 0;
}
