#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int i, p[2] = {}, a = 0;
  cin >> s;
  for (auto x : s) {
    if (x == 'S') p[0]++;
    if (x == 'T') p[1]++;
    if (p[0] < p[1]) a++;
  }
  cout << a << endl;
}
