#include <bits/stdc++.h>
using namespace std;
int main(void) {
  vector<int> a;
  int sum;
  while (true) {
    char c;
    c = getchar();
    if (c == '\n') {
      break;
    } else if (c == 'S') {
      a.push_back(0);
    } else {
      a.push_back(1);
    }
  }
  vector<int> b;
  int now = a[0];
  bool is_first_is_S = a[0] == 0;
  int count = 1;
  for (int i = 1; i < a.size(); i++) {
    if (now == a[i]) {
      count++;
    } else {
      b.push_back(count);
      count = 1;
      now = a[i];
    }
  }
  b.push_back(count);
  sum = 0;
  for (int i = is_first_is_S ? 0 : 1; i < b.size() - 1; i += 2) {
    int dec = min(b[i], b[i + 1]);
    b[i] -= dec;
    b[i + 1] -= dec;
  }
  sum = 0;
  for (int i = 0; i < b.size(); i++) {
    sum += b[i];
  }
  printf("%d\n", sum);
  return 0;
}
