#include <bits/stdc++.h>
using namespace std;
void _main();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  _main();
}
const int inf = INT_MAX / 2;
const long long infl = 1LL << 60;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
void _main() {
  string X;
  cin >> X;
  X += 'X';
  int matchNum = 0;
  int i = 0;
  while (true) {
    int sNum = 0;
    while (X[i] == 'S') {
      ++i;
      ++sNum;
    }
    while (X[i] == 'T' && sNum > 0) {
      ++i;
      --sNum;
      ++matchNum;
    }
    while (X[i] == 'T') {
      ++i;
    }
    if (i >= X.length() - 1) break;
  }
  cout << X.length() - 1 - matchNum * 2 << endl;
}
