#include <bits/stdc++.h>
using namespace std;
int main() {
  string X;
  cin >> X;
  int len = X.size();
  int f = X.size();
  int c = 0;
  for (int i = len; i > 0; i--) {
    if (X[i] == 'T') {
      break;
    } else {
      f = i;
    }
  }
  for (int i = 0; i < len; i++) {
    if (X[i] == 'S') {
      break;
    } else {
      c = i + 1;
    }
  }
  int s = 0;
  int s1 = 0;
  int t1 = 0;
  for (int i = c; i < f; i++) {
    if (X[i] == 'S' && X[i + 1] == 'S') {
      s1++;
    }
    if (X[i] == 'S' && X[i + 1] == 'T') {
      s1++;
    }
    if (X[i] == 'T' && X[i + 1] == 'T') {
      t1++;
    }
    if (X[i] == 'T' && X[i + 1] == 'S') {
      t1++;
      s += min(t1, s1);
      t1 = 0;
      s1 = 0;
    }
  }
  if (X[len - 1] == 'T') {
    t1++;
  }
  s += min(t1, s1);
  cout << len - s * 2;
}
