#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int dx[4] = {0, -1, 1, 0}, dy[4] = {-1, 0, 0, 1};
int solve(string &S) {
  int l = -1, r = -1;
  for (int p = 0; p < (int)S.size() - 1; p++) {
    if (S[p] == 'S' && S[p + 1] == 'T') {
      l = p, r = p + 1;
    }
  }
  if (l < 0) return -1;
  int res = 0;
  while (S[l] == 'S' && S[r] == 'T') {
    res++;
    l--, r++;
  }
  l++, r--;
  S.erase(l, r - l + 1);
  return res;
}
int main() {
  string S;
  cin >> S;
  int len = S.size();
  S = "a" + S + "a";
  int ans = 0;
  while (true) {
    int tmp = solve(S);
    if (tmp < 0) break;
    ans += tmp;
  }
  cout << len - 2 * ans << endl;
}
