#include <bits/stdc++.h>
using namespace std;
string s;
bool vis[2000000 + 10];
int main() {
  cin >> s;
  memset(vis, false, sizeof(vis));
  int before = 0;
  int ans = s.size();
  for (int i = 1; i < s.size(); i++) {
    if (s[before] == 'S' && s[i] == 'T' && vis[before] == false &&
        vis[i] == false) {
      vis[before] = true;
      vis[i] = true;
      ans -= 2;
      if (before != 0) before -= 1;
    } else
      before = i;
  }
  cout << ans;
  return 0;
}
