#include <bits/stdc++.h>
using namespace std;
template <class T>
void cout_vec(const vector<T> &vec) {
  for (auto itr : vec) cout << itr << ' ';
  cout << '\n';
}
const long long mod = 1e9 + 7;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string x;
  cin >> x;
  int n = long long(x.size());
  int now = 0;
  int cnt = 0;
  for (long long i = 0; i < n; i++) {
    if (x[i] == 'S') now++;
    if (x[i] == 'T' && now != 0) {
      cnt++;
      now--;
      if (i + 1 <= n - 1 && x[i + 1] == 'S') now = 0;
    }
  }
  cout << n - 2 * cnt << endl;
}
