#include <bits/stdc++.h>
const int N = 2e6 + 1;
char a[N];
char temp[N];
int main() {
  gets(a);
  char b[2] = {'S', 'T'};
  int i = 0, j = 0, count = 0;
  while (a[i] != NULL) {
    if (b[count] == NULL && count > 0) {
      j = i - count;
      while (a[i] != NULL) {
        a[j++] = a[i++];
      }
      a[j] = NULL;
      i = 0;
      count = 0;
      continue;
    }
    if (a[i] == b[count]) {
      count++;
    } else if (a[i] == b[0]) {
      count = 1;
    } else {
      count = 0;
    }
    i++;
  }
  if (b[count] == NULL && count > 0) {
    a[i - count] = NULL;
  }
  long long ans = strlen(a);
  printf("%d", ans);
  return 0;
}
