#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
char a[N];
int n, k, tot, s[N], ans;
int main() {
  scanf("%s", a + 1);
  n = strlen(a + 1);
  k = 1;
  while (k <= n) {
    if (a[k] != a[k - 1]) {
      if (a[k] == 'S')
        s[++tot]++;
      else
        s[++tot]++;
    } else {
      if (a[k] == 'S')
        s[tot]++;
      else
        s[tot]++;
    }
    k++;
  }
  if (a[1] == 'T') {
    for (int i = 2; i <= tot; i += 2) ans += abs(s[i + 1] - s[i]);
    ans += s[1];
  } else {
    for (int i = 1; i <= tot; i += 2) ans += abs(s[i] - s[i + 1]);
    if (tot % 2 == 1) ans += s[tot];
  }
  cout << ans << endl;
  return 0;
}
