#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 85 - 69;
int lst[maxn], nxt[maxn], n, cnt;
string s;
void remove(int id) {
  if (lst[id] != -1) nxt[lst[id]] = nxt[id];
  lst[nxt[id]] = lst[id];
  return;
}
bool check(int i) {
  if (nxt[i] < n and s[i] == 'S' and s[nxt[i]] == 'T') return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> s;
  n = ((int)(s).size());
  iota(nxt, nxt + maxn, +1);
  iota(lst, lst + maxn, -1);
  for (int i = 0; i < n;) {
    if (check(i)) {
      int tmp;
      if (lst[i] != -1)
        tmp = lst[i];
      else
        tmp = nxt[nxt[i]];
      remove(nxt[i]);
      remove(i);
      i = tmp;
      cnt++;
    } else
      i = nxt[i];
  }
  cout << n - cnt * 2 << endl;
  return 0;
}
