#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  cin >> str;
  long length = str.size();
  long count = 0;
  long minus = 0;
  long flag = 0;
  for (long i = 0; i < length; i++) {
    if (str[i] == 'S') {
      if (flag == 0) {
        count = i;
      }
      flag++;
    }
    if (flag != 0 && str[i] == 'T') {
      flag--;
      if (flag == 0) {
        minus += (i - count + 1);
      }
    }
  }
  length -= minus;
  cout << length << endl;
  return 0;
}
