#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int ans = s.size();
  int ns = 0;
  int nt = 0;
  int i = 0;
  int j = 1;
  while (j < s.size()) {
    if (s[i] == 'S' && s[j] == 'T') {
      ans -= 2;
      if (i == 0 || ns == 0) {
        i = j + 1;
        j = j + 2;
      } else {
        ns -= 1;
        i = i - 1;
        j = j + 1;
      }
    } else if (s[i] == 'S' && s[j] == 'S') {
      ns += 1;
      i = j;
      j = j + 1;
    } else if (s[i] == 'T' && s[j] == 'S') {
      ns = 0;
      i = j;
      j = j + 1;
    } else if (s[i] == 'T' && s[j] == 'T') {
      ns = 0;
      i = j + 1;
      j = j + 2;
    }
  }
  cout << ans << endl;
  return 0;
}
