#include <bits/stdc++.h>
using namespace std;
using p = pair<long long, long long>;
long long dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
long long dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};
int main(void) {
  string s;
  cin >> s;
  long long count = 0;
  long long a = 0, b = 0;
  for (long long i = 0; i < s.length(); i++) {
    if (s[i] == 'S') a++;
    if (s[i] == 'T') b++;
    if (s[i] == 'T' && s[i + 1] == 'S') {
      count += min(a, b);
      a = 0;
      b = 0;
    }
  }
  count += min(a, b);
  long long ans = s.length() - count * 2;
  cout << ans << endl;
  return 0;
}
