#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 = 200011;
char str[MAXN];
int len, a[MAXN], b[MAXN], ans;
int main() {
  scanf("%s", str + 1);
  len = strlen(str + 1);
  for (int i = 1; i <= len; i++) {
    if (str[i] == 'T') continue;
    if (str[i - 1] == 'T')
      a[0]++;
    else if (a[0] == 0 && str[i] == 'S')
      a[0]++;
    a[a[0]]++;
  }
  for (int i = 1; i <= len; i++) {
    if (str[i] == 'S') continue;
    if (str[i - 1] == 'S')
      b[0]++;
    else if (b[0] == 0 && str[i] == 'T')
      b[0]++;
    b[b[0]]++;
  }
  if (str[1] == 'T') {
    int pos = min(a[0], b[0] - 1);
    for (int i = 1; i <= pos; i++) ans += min(a[i], b[i + 1]) * 2;
    printf("%d\n", len - ans);
  } else {
    int pos = min(a[0], b[0]);
    for (int i = 1; i <= pos; i++) ans += min(a[i], b[i]) * 2;
    printf("%d\n", len - ans);
  }
}
