#include <bits/stdc++.h>
using namespace std;
int main(void) {
  string s;
  cin >> s;
  int cnts = 0, cntt = 0, ans = 0;
  bool flag = false;
  int k = 0;
  while (s[k] == 'T') k++;
  int i;
  for (i = k; i < s.size(); ++i) {
    if (s[i] == 'S') {
      if (flag) {
        ans += min(cnts, cntt);
        cnts = cntt = 0;
        flag = false;
      }
      while (s[i] == 'S') {
        cnts++;
        i++;
      }
      i--;
    } else if (s[i] == 'T') {
      while (s[i] == 'T') {
        cntt++;
        i++;
      }
      flag = true;
      i--;
    }
  }
  ans += min(cnts, cntt);
  printf("%d\n", s.size() - ans * 2);
  return 0;
}
