#include <bits/stdc++.h>
template <class T>
inline T chmax(T& a, const T b) {
  return a = (a < b) ? b : a;
}
template <class T>
inline T chmin(T& a, const T b) {
  return a = (a > b) ? b : a;
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = acos(-1);
using namespace std;
signed main() {
  string s;
  cin >> s;
  ll ans = s.size();
  ll cnt1 = 0, cnt2 = 0;
  bool flag = false;
  for (ll i = 0; i < ll(s.size()); ++i) {
    if (s[i] == 'S' || i == s.size() - 1) {
      if (s[i] == 'T') {
        cnt2++;
        flag = true;
      }
      if (flag) {
        ans -= min(cnt1, cnt2) * 2;
        cnt1 = 0;
        cnt2 = 0;
      }
      cnt1++;
      flag = false;
    } else if (s[i] == 'T') {
      cnt2++;
      flag = true;
    }
  }
  cout << ans << endl;
  return 0;
}
