#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  string X;
  cin >> X;
  int ans = 0;
  int i = 0;
  while (i < X.size()) {
    if (X[i] == 'S') {
      int cS = 1;
      int j = i + 1;
      while (j < X.size() && X[j] == 'S') {
        cS++;
        j++;
      }
      if (X[j] == 'T') {
        int cT = 0;
        while (j < X.size() && X[j] == 'T') {
          cT++;
          j++;
        }
        ans += min(cS, cT) * 2;
      }
      i = j;
      continue;
    }
    i++;
  }
  cout << X.size() - ans << endl;
}
