#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1e5 + 10;
long long main() {
  string a;
  cin >> a;
  long long n = a.length();
  long long i = 0;
  long long removed = 0;
  while (i < n) {
    if (a[i] == 'S') {
      long long j = i;
      while (a[j] == 'S' and j < n) j++;
      if (j == n) break;
      long long l = j - i;
      i = j;
      while (a[j] == 'T' and j < n) j++;
      long long r = j - i;
      i = j;
      removed += 2 * min(l, r);
    } else
      i++;
  }
  cout << n - removed;
}
