#include <bits/stdc++.h>
int main() {
  char x[200001];
  scanf("%s", x);
  int l = strlen(x), s = 0, t = 0, flag = 0;
  for (int i = 0; i < l; i++) {
    if (x[i] == 'S') {
      break;
    } else {
      t++;
    }
  }
  for (int i = l - 1; i >= 0; i--) {
    if (x[i] == 'T') {
      break;
    } else {
      s++;
    }
  }
  int ct = 0, cs = 0;
  for (int i = t; i < l - s; i++) {
    if (x[i] == 'S')
      cs++;
    else
      ct++;
  }
  printf("%d", s + t + abs(ct - cs));
  return 0;
}
