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