#include <bits/stdc++.h>
using namespace std;
char S[200010];
int cnt = 0, n, a[200010], b[200010];
bool fla = false;
int main() {
  scanf("%s", S + 1);
  int n = strlen(S + 1);
  if (S[1] == 'S')
    a[++cnt] = 0;
  else
    a[++cnt] = 1;
  b[cnt] = 1;
  for (int i = 2; i <= n; i++)
    if (S[i] != S[i - 1]) {
      if (S[i] == 'S')
        a[++cnt] = 0;
      else
        a[++cnt] = 1;
      b[cnt] = 1;
    } else
      b[cnt]++;
  int st = 1;
  if (a[1] == 1) st++;
  for (int i = st; i < cnt; i++) {
    if (b[i] <= b[i + 1]) {
      b[i + 1] -= b[i];
      b[i] = 0;
      i++;
    } else {
      b[i + 1] = b[i] - b[i + 1];
      a[i + 1] = 0;
      b[i] = 0;
      b[i + 2] += b[i + 1];
      b[i + 1] = 0;
      i++;
    }
  }
  int ans = 0;
  for (int i = 1; i <= cnt; i++) ans += b[i];
  cout << ans;
  return 0;
}
