#include <bits/stdc++.h>
using namespace std;
string genString() {
  string gen = "";
  for (int i = 0; i < 100000; i++) {
    gen += "S";
  }
  for (int i = 0; i < 100000; i++) {
    gen += "T";
  }
  return gen;
}
int main() {
  string x;
  cin >> x;
  bool containST = true;
  int loops = 0;
  bool isAllS = true, isAllT = true;
  for (int i = 0; i < x.length() / 2; i++) {
    if (x[i] != 'S') {
      isAllS = false;
      break;
    }
  }
  for (int i = x.length() / 2; i < x.length(); i++) {
    if (x[i] != 'T') {
      isAllS = false;
      break;
    }
  }
  if (isAllS && isAllT) {
    cout << 0;
    return 0;
  }
  while (containST && x.length() > 1) {
    containST = false;
    string reduced = "";
    int i = 0;
    while (i < x.length()) {
      if ((i < x.length() - 1) && x[i] == 'S' && x[i + 1] == 'T') {
        containST = true;
        i += 2;
      } else {
        reduced += x[i];
        i++;
      }
    }
    x = reduced;
  }
  cout << x.length();
}
