#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int f = 1, ans = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    ans = ans * 10 + c - '0';
    c = getchar();
  }
  return f * ans;
}
const int MAXN = 400011;
char str[MAXN];
int len, a[MAXN], b[MAXN], ans;
int main() {
  scanf("%s", str + 1);
  len = strlen(str + 1);
  int l = 1, r = 1;
  for (int i = 1; i <= len; i++) {
    if (str[i] == 'S') {
      l = i, r = i;
      int Ans = 1;
      for (int j = i + 1; j <= len; j++) {
        if (str[j] == 'S')
          Ans++;
        else
          Ans--;
        if (Ans == 0) {
          r = j;
          break;
        }
      }
      if (l != r) ans += r - l + 1;
      i = r;
    }
  }
  printf("%d\n", len - ans);
  return 0;
}
