#include <bits/stdc++.h>
using namespace std;
char s[(200000 + 5)];
int lst[(200000 + 5)], nxt[(200000 + 5)];
int main() {
  scanf("%s", s + 1);
  int n = strlen(s + 1);
  for (int i = (1); i <= (int)(n); ++i) lst[i] = i - 1, nxt[i] = i + 1;
  nxt[n] = 0;
  int st = -1;
  for (int i = (1); i <= (int)(n - 1); ++i)
    if (s[i] == 'S' && s[i + 1] == 'T') {
      st = i;
      break;
    }
  int ans = n, p;
  while (st != -1) {
    ans -= 2;
    if (!lst[st] && !nxt[nxt[st]]) break;
    if (lst[st])
      p = lst[st], nxt[p] = nxt[nxt[st]];
    else
      p = nxt[nxt[st]], lst[p] = 0;
    while (nxt[p] && (s[p] != 'S' || s[nxt[p]] != 'T')) p = nxt[p];
    st = nxt[p] ? p : -1;
  }
  printf("%d\n", ans);
  return 0;
}
