#include <bits/stdc++.h>
using namespace std;
const long long M = 1e7 + 9;
const long long inf = 1e19;
const int si = 1e5 + 9;
int a[200200];
int t;
int main() {
  string s;
  cin >> s;
  for (int i = 0; i < int(int(s.size())); i++) {
    a[i] += s[i] == 'S';
    if (i) a[i] += a[i - 1];
  }
  bool ok = 1;
  for (int i = int(s.size()) - 1; i >= -1; i--) {
    if (i == -1) {
      ok = 0;
      break;
    }
    if (s[i] == 'T') {
      t = i;
      break;
    }
  }
  if (ok == 0) {
    cout << 0;
  }
  int pos = s.find('S');
  if (pos == -1) {
    cout << 0;
    return 0;
    ;
  }
  int tmp = a[t] - a[pos - 1];
  int tmq = t - pos - tmp + 1;
  if (tmp <= 0 || tmq <= 0) {
    cout << 0;
    return 0;
    ;
  }
  int ans = int(s.size()) - 2 * min(tmp, tmq);
  cout << ans;
  return 0;
  ;
}
