#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;
vector<int> bitSearch(int bit, int n) {
  vector<int> S;
  for (int i = 0; (i) < (int)(n); i++)
    if (bit & (1 << i)) S.push_back(i);
  return S;
}
int d[5 * 100000 + 1];
int main() {
  string s;
  cin >> s;
  int cnt = 0;
  int res = 0;
  for (int i = 0; (i) < (int)(s.size()); i++) {
    if (s[i] == 'S') {
      if (s[i - 1] == 'T' && i > 0) cnt = 0;
      cnt++;
    } else if (s[i] == 'T') {
      if (cnt > 0) res++;
      cnt--;
    }
  }
  cout << s.size() - res * 2 << endl;
}
