#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e18;
const long long mod = (long long)1e9 + 7;
const double eps = (double)1e-9;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};
const int N = 200500;
string s;
int n, nxt[N], prv[N];
inline void del(int pos) {
  int NXT = nxt[pos];
  int PRV = prv[pos];
  nxt[PRV] = NXT;
  prv[NXT] = PRV;
}
int main() {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  cin >> s;
  n = (int)s.size();
  s = "!" + s;
  nxt[0] = 1;
  prv[n + 1] = n;
  for (int i = 1; i <= n; i++) {
    nxt[i] = i + 1;
    prv[i] = i - 1;
  }
  int i = 1, ans = n;
  while (i < n) {
    if (s[i] == 'S' && s[nxt[i]] == 'T') {
      ans -= 2;
      del(i);
      i = prv[i];
    } else
      i = nxt[i];
  }
  cout << ans;
  return 0;
}
