#include <bits/stdc++.h>
using namespace std;
int main() {
  string x;
  cin >> x;
  long long int cnt = 0, tmp = 0, atmp = 0, btmp = 0, m = 0, ans = 0;
  bool f = true;
  for (long long int i = 0; i < x.size(); i++) {
    if (x[i] == 'T') {
      cnt++;
    } else {
      if (i != 0 && x[i - 1] != 'S') {
        tmp = cnt;
      }
      cnt--;
    }
    if (x[i] == 'T') {
      if (tmp >= cnt) {
        ans += 2;
      }
    }
  }
  ans = x.size() - ans;
  cout << ans;
  return 0;
}
