#include <bits/stdc++.h>
char q[200002];
int k, z;
int f(int a, int b) {
  if (a < 0 || q[b] == '\0') return 0;
  z = b;
  if (q[a] == 'S' && q[b] == 'T') {
    k++;
    f(a - 1, b + 1);
  } else if (a + 1 != b)
    return 0;
  z = b;
  f(z, b + 1);
}
int main() {
  int i;
  scanf("%s", &q);
  f(0, 1);
  printf("%d", z - k - 1);
}
