#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  long long a = 0, b = 0, sum = 0, n = s.size();
  bool flag = false;
  for (int i = 0; i < n - 1; i++) {
    if (s[i] == 'S' && s[i + 1] == 'S')
      a++;
    else if (s[i] == 'S' && s[i + 1] == 'T')
      a++;
    else if (s[i] == 'T' && s[i + 1] == 'T')
      b++;
    else {
      b++;
      sum += min(a, b);
      a = max((long long)0, a - b);
      b = 0;
    }
  }
  sum += min(a, b);
  cout << n - 2 * sum;
}
