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