#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  return a % b == 0 ? b : gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
const long long mod = 1000000007;
char x[200001];
int main() {
  char *s, *e, *m;
  scanf("%s", x);
  int len = strlen(x), d = 0;
  e = x;
  while (*e) {
    if (*e == 'S') {
      s = e;
      while (*e && *e == 'S') e++;
      m = e;
      while (*e && *e == 'T') e++;
      d += min(e - m, m - s) * 2;
    } else
      e++;
  }
  printf("%d\n", len - d);
  return 0;
}
