#include <bits/stdc++.h>
using namespace std;
int main() {
  int cnt = 0, cnt2 = 0, i;
  string x;
  cin >> x;
  for (i = 0; i < x.size(); i++) {
    if (x[i] != 'T') break;
  }
  int ck = 0, ans = 0;
  for (; i < x.size(); i++) {
    if (x[i] == 'S' && ck == 1) {
      int l = min(cnt, cnt2);
      ans += l;
      cnt = cnt - l;
      cnt2 = cnt2 - l;
      ck = 0;
    }
    if (x[i] == 'S' && ck == 0) {
      cnt++;
    } else if (x[i] == 'T') {
      cnt2++;
      ck = 1;
    }
  }
  if (ck) {
    ans += min(cnt, cnt2);
  }
  printf("%d", x.size() - (ans * 2));
  return 0;
}
