#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);
string second, ans;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> second;
  for (int i = 0; i < second.length(); ++i) {
    if (second[i] != 'S') ans += second[i];
    if (second[i] == 'S') {
      int pos = i;
      while (pos < second.length() && second[pos] == 'S') pos++;
      int pos1 = pos;
      string cur, cur1;
      while (pos1 < second.length() && second[pos1] == 'T') {
        pos1++;
      }
      if (pos - i > pos1 - pos) {
        for (int j = 0; j < (pos - i) - (pos1 - pos); ++j) {
          ans += 'S';
        }
      } else if (pos - i < pos1 - pos) {
        for (int j = 0; j < -(pos - i) + (pos1 - pos); ++j) {
          ans += 'T';
        }
      }
      i = pos1 - 1;
    }
  }
  cout << ans.length() << endl;
}
