#include <bits/stdc++.h>
int min(int a, int b) {
  if (a > b) {
    return b;
  } else {
    return a;
  }
}
int main() {
  char str[200001] = {};
  int i = 0;
  int j = 0;
  int n = 0;
  int down = 0;
  int up = 0;
  int result = 0;
  scanf(" %s", str);
  for (i = 0; i < 200001; i++) {
    if (str[i] != '\0') {
      n++;
    } else {
      break;
    }
  }
  for (i = 0; i < n; i++) {
    if (str[i] == 'S') {
      if (up) {
        result += 2 * min(up, down);
        down = 1;
        up = 0;
      } else {
        down++;
      }
    } else if (str[i] == 'T') {
      up++;
    }
  }
  result += 2 * min(up, down);
  printf("%d", n - result);
  return 0;
}
