#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAX = 1000000;
const int INF = 1e9;
const double pi = acos(-1);
int main() {
  int n;
  string s;
  cin >> s;
  n = s.size();
  vector<int> vec;
  int sums = 0, sumt = 0;
  for (long long i = 0; i < (n); i++) {
    if (s[i] == 'S') {
      sums++;
      if (sumt) vec.push_back(sumt);
      sumt = 0;
    }
    if (s[i] == 'T') {
      sumt++;
      if (sums) vec.push_back(sums);
      sums = 0;
    }
    if (i == n - 1) {
      if (sumt) vec.push_back(sumt);
      sumt = 0;
      if (sums) vec.push_back(sums);
      sums = 0;
    }
  }
  if (s[0] == 'T') {
    n += vec[0];
    vec.erase(vec.begin());
  }
  long long ans = 0;
  if (vec.size() % 2 == 0) n += vec[vec.size() - 1];
  for (long long i = 0; i < (n / 2); i++) {
    ans += min(vec[i * 2], vec[i * 2 + 1]) * 2;
    vec[i * 2] -= min(vec[i * 2], vec[i * 2 + 1]);
    vec[i * 2 + 1] -= min(vec[i * 2], vec[i * 2 + 1]);
  }
  cout << n - ans << endl;
  return 0;
}
