#include <bits/stdc++.h>
using namespace std;
int main() {
  string x;
  cin >> x;
  vector<int> s(x.size(), 0);
  vector<int> t(x.size(), 0);
  int fs = 210000;
  int lt = -1;
  for (int i = int(0); i < int(x.size()); i++) {
    if (x[i] == 'S') {
      fs = min(fs, i);
      s[i] = 1;
    }
    if (x[i] == 'T') {
      lt = max(lt, i);
      t[i] = 1;
    }
    if (i > 0) {
      s[i] = s[i] + s[i - 1];
      t[i] = t[i] + t[i - 1];
    }
  }
  int ans = (int)(x.size() - 2 * min(t[x.size() - 1] - t[fs], s[lt]));
  cout << ans << endl;
  return 0;
}
