#include <bits/stdc++.h>
using namespace std;
int h[200008][2] = {0};
int main() {
  char c;
  int n = 0;
  while (cin >> c) {
    n++;
    if (c == 'S') {
      h[n][1] = h[n - 1][1] + 1;
      h[n][0] = h[n - 1][0];
    } else {
      h[n][1] = h[n - 1][1];
      h[n][0] = h[n - 1][0] + 1;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    h[i][0] = n / 2 - h[i][0];
    if (ans < min(h[i][0], h[i][1])) ans = min(h[i][0], h[i][1]);
  }
  cout << n - 2 * ans << endl;
}
