#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
char str[MAXN];
int len;
int main(void) {
  scanf("%s", str);
  len = strlen(str);
  int x = 0, y = 1;
  while (x < y && x < len - 1 && y < len) {
    if (str[x] == 'S' && str[y] == 'T') {
      str[x] = ' ';
      str[y] = ' ';
      if (x == 0) {
        x = 2, y = 3;
      } else {
        x--;
        y++;
      }
    } else if (str[x] == ' ' && str[y] != ' ') {
      x++;
      if (x == y) y++;
    } else {
      x++, y++;
    }
  }
  int newLen = 0;
  for (int i = 0; i < len; i++)
    if (str[i] != ' ') newLen++;
  printf("%d\n", newLen);
  return 0;
}
