#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
char c, s[233333];
int t;
int main() {
  s[0] = 'A';
  t = 1;
  long long ans = 0, now = 0;
  while (~scanf("%c", &c)) {
    now++;
    if (c == 'T') {
      if (s[t - 1] == 'S') {
        ans++;
        t--;
        continue;
      }
      s[t++] = c;
    } else {
      s[t++] = c;
    }
  }
  cout << now - 2 * ans << endl;
  return 0;
}
