#include <bits/stdc++.h>
using namespace std;
char s[2000000];
int main() {
  scanf("%s", s);
  queue<pair<long long, long long> > que;
  long long len = strlen(s);
  long long ans = len;
  for (long long i = 0; i < len - 1; i++) {
    if (s[i] == 'S' && s[i + 1] == 'T') {
      que.push(pair<long long, long long>(i, i + 1));
      ans -= 2;
    }
  }
  while (!que.empty()) {
    pair<long long, long long> i = que.front();
    que.pop();
    if (i.first > 0 && i.second + 1 < len && s[i.first - 1] == 'S' &&
        s[i.second + 1] == 'T') {
      que.push(pair<long long, long long>(i.first - 1, i.second + 1));
      ans -= 2;
    }
  }
  printf("%lld\n", max(0LL, ans));
}
