#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  string s;
  cin >> s;
  string cpy = s;
  while (s.front() == 'T') s.erase(s.begin());
  while (s.back() == 'S') s.pop_back();
  ll scnt, tcnt;
  scnt = tcnt = 0;
  for (ll i = 0; i < s.size(); ++i) {
    if (s[i] == 'S')
      scnt++;
    else
      tcnt++;
  }
  cout << cpy.size() - s.size() + abs(scnt - tcnt) << endl;
}
