#include <bits/stdc++.h>
using namespace std;
string x;
long long len, s, t, ans;
bool m;
signed main() {
  cin >> x;
  len = x.size();
  ans = len;
  for (long long i = 0; i < len - 1; i++) {
    if (x[i] == 'S') {
      if (m) {
        ans -= min(s, t) * 2;
        m = false;
      }
      t = 0;
      s++;
    } else {
      t++;
      if (!m) s = 0;
    }
    if (x[i] == 'S' && x[i + 1] == 'T') {
      m = true;
      if (i == len - 2) {
        ans -= 2;
      }
    }
  }
  cout << ans << endl;
}
