#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
struct kkk {
  int lt, nt;
  char c;
} a[N];
int n, ans;
void clrs(int i, int j) {
  a[a[i].lt].nt = a[j].nt;
  a[a[j].nt].lt = a[i].lt;
}
int main() {
  char ch;
  a[0].nt = 1;
  for (int i = 1, ch = getchar(); ch != EOF; ++i, ch = getchar()) {
    a[i].c = ch;
    a[i].lt = i - 1;
    a[i].nt = i + 1;
    ++n;
  }
  a[n + 1].lt = n;
  ans = n;
  for (int i = 1; i < n; i = a[i].nt) {
    if (a[i].c == 'S' && a[a[i].nt].c == 'T') {
      i = a[i].lt;
      clrs(a[i].nt, a[a[i].nt].nt);
      i = a[i].lt;
      ans -= 2;
    }
  }
  printf("%d", ans);
  return 0;
}
