#include <bits/stdc++.h>
using namespace std;
char s[500005];
int main() {
  scanf(" %s", s);
  int cnt = 0, ans = 0;
  for (int i = 0; s[i]; i++) {
    if (s[i] == 'T') cnt--;
    if (s[i] == 'S') cnt++;
    if (cnt < 0) ans++;
  }
  printf("%d\n", ans);
  return 0;
}
