#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int len = s.length();
  int sp = 0;
  int next_sp = 0;
  int tp = 0;
  int next_tp = 0;
  int ans = 0;
  int scnt = 0;
  int tcnt = 0;
  int ss = 0;
  while (1) {
    sp = s.find('S', ss);
    if (sp == -1) {
      break;
    }
    tp = s.find('T', sp);
    if (tp == -1) {
      break;
    }
    scnt = tp - sp;
    next_sp = s.find('S', tp);
    if (next_sp == -1) {
      next_sp = len;
    }
    tcnt = next_sp - tp;
    if (scnt >= tcnt) {
      ans += tcnt;
    } else {
      ans += scnt;
    }
    ss = next_sp - 1;
  }
  cout << len - (ans * 2) << endl;
}
