#include <bits/stdc++.h>
using namespace std;
__attribute__((constructor)) void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
int main() {
  string x;
  cin >> x;
  int s = 0, t = 0;
  for (int i = (0); i < (x.length() - 1); i++) {
    if (x[i] == 'S' && x[i + 1] == 'T') {
      for (int j = (i + 1); j < (x.length()); j++) {
        if (x[j] == 'T')
          t++;
        else {
          int p = 0;
          for (int k = j; k < x.length() - 1; k += 2) {
            if (x[k] == 'S' && x[k + 1] == 'T') p++;
          }
          cout << x.length() - ((min(s, t) + p) * 2 + 2) << endl;
          return 0;
        }
      }
    } else if (x[i] == 'S')
      s++;
    else
      s = 0;
  }
  if (t) {
    cout << x.length() - min(s, t) * 2 << endl;
  } else {
    cout << x.length() << endl;
  }
}
