#include <bits/stdc++.h>
using namespace std;
int main() {
  string X;
  cin >> X;
  int i, j, ct = 0;
  for (i = 0; i < X.size(); i = j) {
    int s1 = 0, t1 = 0;
    for (j = i; j < X.size() && X[j] == 'S'; ++j) ++s1;
    for (; j < X.size() && X[j] == 'T'; ++j) ++t1;
    ct += abs(s1 - t1);
  }
  cout << ct << endl;
  return 0;
}
