#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, i, sum;
  char s;
  i = 0;
  h = 0;
  while (cin >> s) {
    if (s == 'S' && h == 1) {
      if (i >= 0)
        sum += i;
      else
        sum += i * -1;
      i = 1;
      h = 0;
    } else if (s == 'T') {
      i--;
      h = 1;
    } else if (s == 'S') {
      i++;
      h = 0;
    }
  }
  if (i >= 0)
    sum += i;
  else
    sum += i * -1;
  cout << sum << endl;
  return 0;
}
