#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string X;
  cin >> X;
  int ans = X.size();
  int Scnt = 1, Tcnt = 0;
  for (int i = 1; i < X.size(); i++) {
    if (X[i] == 'S' && X[i - 1] == 'S') {
      Scnt++;
    } else if (X[i] == 'T' && X[i - 1] == 'T') {
      Tcnt++;
    } else if (X[i] == 'S' && X[i - 1] == 'T') {
      ans -= 2 * min(Scnt, Tcnt);
      cerr << ans << endl;
      Scnt = 1, Tcnt = 0;
    } else
      Tcnt++;
  }
  if (Tcnt > 0) ans -= 2 * min(Scnt, Tcnt);
  cout << ans << endl;
  return 0;
}
