#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template <class A, class B>
inline bool chmax(A &a, const B &b) {
  return b > a ? a = b, 1 : 0;
}
template <class A, class B>
inline bool chmin(A &a, const B &b) {
  return b < a ? a = b, 1 : 0;
}
constexpr const int INF = 0x3f3f3f3f;
constexpr const i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr const int MOD = int(1e9) + 7;
struct FastIO {
  FastIO() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
  }
} fastIO_ydk;
signed main() {
  using P = pair<char, int>;
  string x;
  cin >> x;
  const int L = x.length();
  vector<P> a;
  int cnt = 1;
  for (int i = 1; i < L; ++i) {
    if (x[i - 1] == x[i]) {
      ++cnt;
    } else {
      a.emplace_back(x[i - 1], cnt);
      cnt = 1;
    }
  }
  a.emplace_back(x.back(), cnt);
  ;
  for (auto e : a) {
    ;
  }
  int ans = L;
  for (int i = 1; i < a.size(); ++i) {
    if (a[i - 1].first == 'S' && a[i].first == 'T') {
      ans -= 2 * min(a[i - 1].second, a[i].second);
    }
  }
  cout << (ans) << '\n';
  return 0;
}
