#include <bits/stdc++.h>
using namespace std;
int l, r;
char h;
int ans;
int main() {
  while (cin >> h) {
    if (h == 'S') l++;
    if (h == 'T') r++;
    if (r > l) {
      ans++;
    }
  }
  if (l > r) {
    ans++;
  }
  cout << ans;
  return 0;
}
