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