#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
template <class T>
T gcd(T a, T b) {
  return ((b == 0) ? a : gcd(b, a % b));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  int cur = 1;
  int prev = -1, tot = 0;
  for (int i = (int)(1); i < (int)(n); i++) {
    if (s[i] != s[i - 1]) {
      if (s[i - 1] == 'T') {
        if (prev != -1) tot += min(cur, prev) * 2;
      }
      if (s[i - 1] == 'S') prev = cur;
      cur = 1;
    } else {
      cur++;
    }
  }
  if (s[n - 1] == 'T') {
    if (prev != -1) tot += min(cur, prev) * 2;
  }
  if (s[n - 1] == 'S') prev = cur;
  cout << n - tot << endl;
  return 0;
}
