#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = (1LL << 60);
constexpr ll MOD = (1e9 + 7);
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
template <class T>
vector<vector<T>> vvt(T init, ll m, ll n) {
  vector<vector<T>> ans = vector<vector<T>>(m, vector<T>(n, init));
  return move(ans);
}
template <class T>
vector<T> vt(T init, ll n) {
  vector<T> ans = vector<T>(n, init);
  return move(ans);
}
template <class T>
T maxVec(vector<T>& v) {
  T ans = -INF;
  for (ll i = 0; i < (v.size()); ++i) {
    ans = max(ans, v[i]);
  }
  return ans;
}
bool judge(ll n) {
  for (ll i = 2; i * i <= n; i++)
    if (n %= i) return false;
  return true;
}
template <class C>
void print(const C& c, std::ostream& os = std::cout) {
  std::copy(std::begin(c), std::end(c),
            std::ostream_iterator<typename C::value_type>(os, ", "));
  os << std::endl;
}
ll count(ll n, ll r) {
  ll ans = 0, check = 1;
  for (ll i = 0; i < (r); ++i) {
    if ((n & check) > 0) {
      ans++;
    }
    check = check << 1;
  }
  return ans;
}
bool sortreverse(ll a, ll b) { return a > b; }
bool kansu(pll a, pll b) { return a.first < b.first; }
ll kiriage(ll a, ll b) {
  if (a % b == 0) return a / b;
  return a / b + 1;
}
int main() {
  string s;
  cin >> s;
  ll scount = 0, tcount = 0, scheck = 0, tcheck = 0, n = s.size();
  for (ll i = 0; i < (n); ++i) {
    if (s[i] == 'S') scheck = 1;
    if (scheck && s[i] == 'T') tcount++;
    if (s[n - 1 - i] == 'T') tcheck = 1;
    if (tcheck && s[n - 1 - i] == 'S') scount++;
  }
  printf("%lld\n", n - 2 * min(scount, tcount));
}
