#include <bits/stdc++.h>
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using ll = long long;
using ld = long double;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll s[210000], t[210000];
int main() {
  ll ans = 0;
  string x;
  cin >> x;
  ll cs = 0, ct = 0;
  ll cnt = 0;
  for (ll i = ll(0); i < ll(x.length() - 1); i++) {
    if (x[i] == 'S' && x[i + 1] == 'T') {
      cnt++;
      x[i] = 'A';
      x[i + 1] = 'A';
    }
  }
  for (ll i = ll(0); i < ll(x.length()); i++) {
    if (x[i] == 'S') cs++;
    s[i] = cs;
  }
  for (ll i = ll(x.length() - 1); i >= ll(0); i--) {
    if (x[i] == 'T') ct++;
    t[i] = ct;
  }
  for (ll i = ll(0); i < ll(x.length()); i++) ans = max(ans, min(s[i], t[i]));
  cout << x.length() - ans * 2 - cnt * 2;
}
