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