#include <bits/stdc++.h>
using namespace std;
int n, ans, a;
int main() {
  string s;
  cin >> s;
  n = s.size();
  for (int i = 0; i < n; i++) {
    if (s[i] == 'T') {
      if (a == 0) {
        ans++;
      }
      if (a > 0) {
        a--;
        ans--;
      }
    }
    if (s[i] == 'S') {
      a++;
      ans++;
    }
    if (s[i] == 'T' and s[i + 1] == 'S') {
      a = 0;
    }
  }
  cout << ans;
  return 0;
}
