#include <bits/stdc++.h>
char letter[200001];
int next[200000];
int prev[200000];
int num;
int start;
int end;
int sum;
bool flag = true;
int main() {
  scanf("%s", letter);
  for (int i = 0; i <= 200000; i++) {
    next[i] = i + 1;
    prev[i] = i - 1;
    if (letter[i] == NULL) {
      num = i;
      break;
    }
  }
  sum = num;
  start = 0;
  while (flag) {
    for (int i = start; next[i] < num;) {
      if (letter[i] == 'S') {
        if (letter[next[i]] == 'T') {
          if (prev[i] >= 0) {
            if (next[next[i]] < num) {
              next[prev[i]] = next[next[i]];
              prev[next[next[i]]] = prev[i];
              start = prev[i];
            } else {
              flag = false;
            }
          } else {
            if (next[next[i]] < num) {
              prev[next[next[i]]] = -1;
              start = next[next[i]];
            } else {
              flag = false;
            }
          }
          sum -= 2;
          break;
        }
      }
      if (next[next[i]] >= num) {
        flag = false;
      }
      i = next[i];
    }
  }
  printf("%d\n", sum);
  return 0;
}
