#include <bits/stdc++.h>
using namespace std;
int main() {
  string tmp;
  cin >> tmp;
  int s[tmp.size()], t[tmp.size()];
  int st[tmp.size()];
  fill(st, st + tmp.size(), -1);
  for (int i = 0; i < tmp.size(); i++) {
    if (i == 0)
      s[i] = (tmp[i] == 'S' ? 1 : 0);
    else {
      if (tmp[i] == 'S') {
        if (tmp[i - 1] == 'S')
          s[i] = s[i - 1] + 1;
        else
          s[i] = 1;
      } else {
        s[i] = 0;
        st[i - s[i - 1] - 2] = i - 1;
      }
    }
  }
  for (int i = tmp.size() - 1; i >= 0; i--) {
    if (i == tmp.size() - 1) {
      t[i] = (tmp[i] == 'T' ? 1 : 0);
    } else {
      if (tmp[i] == 'T') {
        if (tmp[i + 1] == 'T')
          t[i] = t[i + 1] + 1;
        else
          t[i] = 1;
      } else
        t[i] = 0;
    }
  }
  int num = 0;
  for (int i = 0; i < tmp.size() - 1; i++) {
    if (tmp[i] == 'S' && tmp[i + 1] == 'T') {
      num += min(s[i], t[i + 1]);
      if (s[i] > t[i + 1]) s[st[i + 1]] += (s[i] - t[i + 1]);
    }
  }
  cout << tmp.size() - 2 * num << endl;
  return 0;
}
