#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  long long n = s.size(), c = 0, ans;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'T')
      --c;
    else
      ++c;
    if (c < 0) ++ans, ++c;
  }
  cout << ans * 2 << endl;
}
