#include <bits/stdc++.h>
using namespace std;
int main(void) {
  string s;
  cin >> s;
  int S = 0, T = 0, l = 0, ans = 0;
  while (l < s.size()) {
    while (s[l] == 'S') {
      S++;
      l++;
    }
    while (s[l] == 'T') {
      T++;
      l++;
    }
    ans += min(S, T);
    S = 0, T = 0;
  }
  cout << s.size() - ans * 2 << endl;
}
