#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const int maxN = 103000;
void solve() {
  string s;
  cin >> s;
  long long cnt = 0;
  stack<char> st;
  for (int i = 0; i < (s.length()); ++i) {
    if (s[i] == 'S') {
      st.push('S');
      continue;
    }
    if (s[i] == 'T') {
      if (st.empty())
        st.push('T');
      else if (st.top() == 'S') {
        cnt += 2;
        st.pop();
      } else
        st.push('T');
    }
  }
  cout << cnt << endl;
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  solve();
  return 0;
}
