#include <bits/stdc++.h>
using namespace std;
int main() {
  string a;
  cin >> a;
  int lo = 0, hi = 1;
  int count = 0;
  for (int i = 0; i < a.size(); i++) {
    if (a[lo] == 'S' && a[hi] == 'T') {
      hi++;
      lo--;
      if (lo < 0) {
        lo = hi - 1;
      }
      count += 2;
    } else {
      lo++;
      hi++;
    }
  }
  cout << a.size() - count << endl;
}
