#include <bits/stdc++.h>
const long long MOD = 1e9 + 7;
using namespace std;
int main() {
  string x;
  cin >> x;
  long long t = 0, s = 0;
  long long f = 0, l = x.size() - 1;
  while (1) {
    if (x[f] == 'T') {
      f++;
    } else {
      break;
    }
  }
  t = f;
  while (1) {
    if (x[l] == 'S') {
      l--;
      s++;
    } else {
      break;
    }
  }
  long long ans = x.size() - min(x.size() / 2 - t, x.size() / 2 - s) * 2;
  cout << ans << endl;
}
