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