#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
int main() {
  string s;
  cin >> s;
  int n = s.size();
  int ans = n;
  int tmpS = 0, tmpT = 0, i = 0;
  while (i < n - 1) {
    if (s[i] == 'S')
      tmpS++;
    else if (s[i] == 'T')
      tmpT++;
    if (s[i] == 'T' && s[i + 1] == 'S') {
      ans -= 2 * min(tmpS, tmpT);
      tmpS = 0;
      tmpT = 0;
    }
    i++;
  }
  if (s[n - 2] == 'S' && s[n - 1] == 'T') ans -= 2;
  cout << ans << endl;
  return 0;
}
