#include <bits/stdc++.h>
using namespace std;
const int N = 200003;
int n, ans, cnt;
char str[N];
int main() {
  scanf("%s", str + 1);
  n = strlen(str + 1);
  for (register int i = 1; i <= n; i++)
    if (str[i] == 'S') {
      if (str[i - 1] == 'T') cnt = 0;
      ++cnt;
    } else if (str[i] == 'T' && cnt > 0)
      --cnt, ++ans;
  printf("%d", n - (ans << 1));
}
