#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;
  itr = 0;
  ll Scnt = 0;
  while (Scnt >= 0 && itr < N) {
    if (X[itr] == 'S') {
      Scnt++;
    } else {
      Scnt--;
    }
    itr++;
  }
  itr--;
  if (itr > 0) {
    X.erase(X.begin(), X.begin() + itr + 1);
  }
  N = (static_cast<ll>((X).size()));
  itr = 0;
  ll Tcnt = 0;
  while (Tcnt >= 0 && itr < N) {
    if (X[itr] == 'T') {
      Tcnt++;
    } else {
      Tcnt++;
    }
    itr++;
  }
  itr--;
  if (itr > 0) {
    X.erase(X.end(), X.end() - itr - 1);
  }
  N = (static_cast<ll>((X).size()));
  if (N == 0) {
    cout << 0 << endl;
    return 0;
  }
  ll Tbegin = 0;
  ll Send = 0;
  for (ll i = (0); i <= (N - 1); i++) {
    if (X[i] == 'T') {
      Tbegin++;
    } else {
      break;
    }
  }
  for (ll i = (0); i <= (N - 1); i++) {
    if (X[N - i - 1] == 'S') {
      Send++;
    } else {
      break;
    }
  }
  cout << max(Tbegin, Send) * 2 << endl;
  return 0;
}
