#include <bits/stdc++.h>
using namespace std;
int main() {
  int s = 0;
  int t = 0;
  char c;
  int del = 0;
  int count = 0;
  while (scanf("%c", &c) > 0) {
    if (s != 0 && t != 0 && c == 'S') {
      del += 2 * min(t, min(10000, s));
      s = 0;
      t = 0;
    }
    if (t == 0 && c == 'S') {
      s++;
    }
    if (s != 0 && c == 'T') {
      t++;
    }
    count++;
  }
  if (s != 0 && t != 0) del += 2 * min(s, min(t, 10000));
  int answer = count - del;
  printf("%d", answer);
}
