#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int i = 0, j, k, tlen, slen, stlen = 0;
  string s;
  cin >> s;
  for (; (s[i] == 'T') && (i < s.length()); i++) {
  }
  while (i < s.length()) {
    j = i;
    for (; (s[i] == 'S') && (i < s.length()); i++) {
    }
    slen = i - j;
    k = i;
    for (; (s[i] == 'T') && (i < s.length()); i++) {
    }
    tlen = i - k;
    stlen += min(slen, tlen) * 2;
  }
  cout << s.length() - stlen;
}
