#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int64_t inf64 = 1e18;
const double eps = 1e-9;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}
void solve() {
  string x;
  cin >> x;
  vector<int> next, prev;
  for (int i = (0); i < (x.size()); ++i) {
    next.push_back(i + 1);
    prev.push_back(i - 1);
  }
  int i = 0, ans = x.size();
  while (i < x.size() - 1) {
    if (x[i] == 'S' and x[next[i]] == 'T') {
      ans -= 2;
      int j = prev[i];
      if (j >= 0) {
        next[j] = next[next[i]];
        i = j;
      } else {
        i = next[next[i]];
        prev[i] = -1;
      }
    } else
      i = next[i];
  }
  cout << ans << endl;
}
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(10);
  solve();
  return 0;
}
