#include <bits/stdc++.h>
using namespace std;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;
using ll = long long;
using PL = P<ll, ll>;
using PS = P<string, ll>;
using VI = V<int>;
using VVI = V<VI>;
using VL = V<ll>;
using VVL = V<VL>;
using VS = V<string>;
using VB = V<bool>;
using VVB = V<VB>;
using VPL = V<PL>;
using VPS = V<PS>;
template <typename T>
T square(T a) {
  return a * a;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string X;
  cin >> X;
  ll N = (static_cast<ll>((X).size()));
  ll itr;
  ll Tbegin = 0;
  itr = 0;
  ll Scnt = 0;
  while (Scnt >= 0 && itr < N) {
    if (X[itr] == 'S') {
      Scnt++;
    } else {
      Scnt--;
    }
    itr++;
  }
  itr--;
  cout << "itr"
       << " = " << itr << endl;
  ;
  if (itr == N - 1) {
    cout << 0 << endl;
    return 0;
  }
  while (X[itr] == 'T' && itr < N) {
    Tbegin++;
    itr++;
  }
  cout << "Tbegin"
       << " = " << Tbegin << endl;
  ;
  ll Send = 0;
  itr = N - 1;
  ll Tcnt = 0;
  while (Tcnt >= 0 && itr >= 0) {
    if (X[itr] == 'T') {
      Tcnt++;
    } else {
      Tcnt--;
    }
    itr--;
  }
  itr++;
  cout << "itr"
       << " = " << itr << endl;
  ;
  while (X[itr] == 'S' && itr >= 0) {
    Send++;
    itr--;
  }
  cout << "Send"
       << " = " << Send << endl;
  ;
  cout << max(Tbegin, Send) * 2 << endl;
  return 0;
}
