#include <bits/stdc++.h>
using namespace std;
constexpr int64_t INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr long long mod = 1000000007;
template <class A, class B>
inline bool chmax(A &a, const B &b) {
  return b > a && (a = b, true);
}
template <class A, class B>
inline bool chmin(A &a, const B &b) {
  return b < a && (a = b, true);
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string x;
  cin >> x;
  int64_t n = x.size();
  int64_t t = 0, s = 0, sum = 0;
  bool flg = false;
  for (int64_t i = 0; i < (n); ++i) {
    if (flg) {
      if (x[i] == 'T') {
        ++t;
      } else {
        sum += min(s, t);
        s = 1;
        t = 0;
        flg = false;
      }
    } else {
      if (x[i] == 'S') {
        ++s;
      } else {
        ++t;
        flg = true;
      }
    }
  }
  cout << n - (sum + min(s, t)) * 2 << '\n';
  return 0;
}
