#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  return a % b == 0 ? b : gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
  return (a / gcd(a, b)) * b;
}
int main() {
  string s;
  cin >> s;
  int n = s.size(), ans = n, scount = 0, tcount = 0;
  for (int i = 0; i < n - 1; i++) {
    if (s[i] == 'S' && s[i + 1] == 'T') {
      scount++, tcount++;
      i += 2;
      while (s[i] == 'T') i++, tcount++;
      i--;
      ans -= (2 * min(scount, tcount));
      scount -= min(scount, tcount), tcount -= min(scount, tcount);
      if (tcount > scount) tcount = 0;
    } else if (s[i] == 'S' && s[i] == 'S')
      scount++;
  }
  cout << ans;
}
