#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
template <class T>
ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}
void solve(std::string X) {
  char c = *X.begin();
  ll s_num = 0;
  ll t_num = 0;
  ll ans = 0;
  if (c == 'S')
    s_num++;
  else
    t_num++;
  for (auto i = X.begin() + 1; i != X.end(); i++) {
    if (*i == 'S' and c == 'S') {
      s_num++;
    } else if (*i == 'T' and c == 'S') {
      t_num = 1;
      c = 'T';
    } else if (*i == 'T' and c == 'T') {
      t_num++;
    } else if (*i == 'S' and c == 'T') {
      if (s_num > t_num) {
        ans += t_num;
        s_num -= t_num;
      } else if (t_num > s_num) {
        ans += s_num;
        t_num -= s_num;
      } else {
        ans += s_num;
        s_num = 0;
        t_num = 0;
      }
      s_num++;
      t_num = 0;
      c = 'S';
    }
  }
  ans += min(s_num, t_num);
  std::cout << X.size() - ans * 2 << std::endl;
}
int main() {
  std::string X;
  std::cin >> X;
  solve(X);
  return 0;
}
