#include <bits/stdc++.h>
using namespace std;
char s[200001];
void solve() {
  cin >> s;
  bool flag = false;
  int cntS = 0;
  int ans = 0, cnt = 0;
  for (int i = 0; s[i] != '\0'; i++) {
    cnt++;
    if (s[i] == 'S') {
      if (flag) cntS = 0;
      cntS++;
      flag = false;
    }
    if (s[i] == 'T' && cntS > 0) {
      cntS--;
      flag = true;
      ans++;
    }
  }
  cout << cnt - 2 * ans << endl;
}
int main() {
  solve();
  return 0;
}
