#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  s += 'S';
  int res = s.length() - 1;
  int cnt_s = 0, cnt_t = 0;
  if (s[0] == 'S')
    cnt_s++;
  else
    cnt_t++;
  for (int i = 1; i < s.length(); i++) {
    if (s[i] == 'S') {
      if (s[i - 1] == 'T') {
        res -= 2 * min(cnt_s, cnt_t);
        cnt_s = cnt_t = 0;
      }
      cnt_s++;
    } else {
      cnt_t++;
    }
  }
  cout << res << endl;
}
