#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int num_s = 0, num_t = 0;
  int del = 0;
  for (int i = 0; i < s.size(); i++) {
    int j = i;
    if (s[i] == 'S') {
      num_s = 0;
      while (j < s.size() && s[j] == 'S') {
        j++;
        num_s++;
      }
      i = j - 1;
    }
    if (s[i] == 'T') {
      num_t = 0;
      while (j < s.size() && s[j] == 'T') {
        j++;
        num_t++;
      }
      i = j - 1;
      del += 2 * min(num_s, num_t);
      num_s = num_t = 0;
    }
  }
  cout << s.size() - del << endl;
  return 0;
}
