#include <bits/stdc++.h>
using namespace std;
vector<pair<char, int> > v;
int main() {
  string s;
  cin >> s;
  int S = 0;
  int T = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'S') {
      if (T) v.push_back(make_pair('T', T));
      T = 0;
      S++;
    } else {
      if (S) v.push_back(make_pair('S', S));
      S = 0;
      T++;
    }
  }
  if (T) v.push_back(make_pair('T', T));
  if (S) v.push_back(make_pair('S', S));
  int n = (int)v.size();
  int cut = 0;
  for (int i = 0; i < (n - 1); i++) {
    pair<char, int> p1;
    pair<char, int> p2;
    p1 = v[i];
    p2 = v[i + 1];
    if (p1.first == 'S') {
      cut += 2 * min(p1.second, p2.second);
    }
  }
  cout << s.length() - cut << endl;
  return 0;
}
