#include <bits/stdc++.h>
using namespace std;

void solve(std::string X) {
  int tmp = 0;
  int tmp1 = 0;
  for(int i= 0,i<X.size();i++){
    if(X[i] == 'T'){
      if(tmp1 == 0)tmp++;
      else tmp1++;
    }
    else tmp1--;
  }
  cout<<tmp-tmp1;;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  std::string X;
  std::cin >> X;
  solve(X);
  return 0;
}
