#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string st;
  cin >> st;
  ll t = 0, s = 0;
  rep(i, st.size()) {
    if(st[i] == 'T') {
      if(s > 0)
        s--;
      else
        t++;
    } else {
      s++;
    }
  }
  cout << t + s << endl;
}
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
	string x; cin >> x;
	int n = x.size();
	vector<char> st;
	REP(i, n) {
		if (x[i] == 'S')
			st.push_back('S');
		else {
			if (st.empty())
				st.push_back('T');
			else if (st.back() == 'S')
				st.pop_back();
			else if (st.back() == 'T')
				st.push_back('T');
		}
	}
	cout << st.size() << '\n';
	return 0;
}
