#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int minx = 2147483647, x = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'T')
      x--;
    else
      x++;
    minx = min(minx, x);
  }
  cout << minx << endl;
}
