#include <bits/stdc++.h>
int main() {
  int str_n;
  char str[300000];
  scanf("%s", str);
  str_n = strlen(str);
  int ans = str_n;
  int x;
  for (int i = 0; str[i + 1] != '\0'; i++) {
    if (str[i] == 'S' && str[i + 1] == 'T') {
      str[i] = str[i + 1] = 'x';
      ans -= 2;
      for (int j = i - 1, x = 3; 0 <= j && j + x < str_n; j++, x += 2) {
        if (str[j] == 'S' && str[j + x] == 'T') {
          str[j] = str[j + x] = 'x';
          ans -= 2;
        } else {
          break;
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
