#include <bits/stdc++.h>
using namespace std;
int solve(string x) {
  int ret = 0;
  int n = x.size();
  int cnt_s = 0;
  int cnt_t = 0;
  for (int i = 0; i < n; i++) {
    if (x.at(i) == 'S') {
      if (i > 0 && x.at(i - 1) == 'T') {
        ret += abs(cnt_s - cnt_t);
        cnt_s = 1;
        cnt_t = 0;
      } else {
        cnt_s++;
      }
    } else {
      cnt_t++;
    }
  }
  ret += abs(cnt_s - cnt_t);
  return ret;
}
int main() {
  string x;
  cin >> x;
  cout << solve(x) << endl;
  return 0;
}
