#include <bits/stdc++.h>
using namespace std;
vector<bool> gen_sosuu(vector<bool> sosuu) {
  int size = sosuu.size();
  for (long long int i = 0; i < (int)(size); i++) {
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  for (long long int i = (2); i < (int)(sqrt(size) + 1); i++) {
    if (sosuu[i] == false) continue;
    for (int j = 2; i * j < size; j++) {
      sosuu[i * j] = false;
    }
  }
  return sosuu;
}
string s;
long long int l = 1 << 30;
long long int r = 0;
;
int cs = 0;
int ct = 0;
int cnt = 0;
int main() {
  cin >> s;
  for (long long int i = 0; i < (int)(s.size()); i++) {
    if (s[i] == 'S') l = min(l, i);
    if (s[i] == 'T') r = max(r, i);
  }
  for (long long int i = (l); i < (int)(r + 1); i++) {
    if (s[i] == 'S') cs++;
    if (s[i] == 'T') ct++;
    if (ct > cs) {
      cnt += cs;
      cs = 0;
      ct = 0;
    }
  }
  cnt += cs;
  cout << s.size() - cnt * 2 << endl;
}
