#include <bits/stdc++.h>
using namespace std;
int main() {
  string x;
  cin >> x;
  int y = 0;
  int ans = 0;
  for (int unsigned i = 0; i < x.size(); i++) {
    if (x[i] == 'S') y++;
    if (x[i] == 'T') y--;
    if (y < 0) ans++;
  }
  cout << ans << endl;
  return 0;
}
