#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;
  const int n = s.size();
  vector<int> l(n + 1), r(n + 1);
  for (int i = 0; i <= n; ++i) {
    l[i] = i - 1;
    r[i] = i + 1;
  }
  for (int i = 0; r[i] < n;) {
    const int x = i, y = r[i];
    if (s[x] == 'S' && s[y] == 'T') {
      int next = l[x];
      if (next < 0) {
        next = r[y];
      }
      s[x] = s[y] = ' ';
      const int t = l[x];
      if (t >= 0) {
        r[t] = r[y];
      }
      l[r[y]] = l[t];
      i = next;
    } else {
      i = r[i];
    }
  }
  int answer = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] != ' ') {
      ++answer;
    }
  }
  cout << answer << endl;
  return 0;
}
