#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  string X;
  cin >> X;
  int ret = 0;
  vector<pair<char, int> > v;
  for (int i = (0); i < (int)(X.size()); i++) {
    int cnt = 1;
    int j = i + 1;
    while (j < X.size() && X[j] == X[i]) {
      j++;
      cnt++;
    }
    v.push_back(make_pair(X[i], cnt));
    i = j - 1;
  }
  for (int i = (0); i < (int)(v.size() - 1); i++) {
    if (v[i].first == 'S' && v[i + 1].first == 'T') {
      int mn = min(v[i].second, v[i + 1].second);
      v[i].second -= mn;
      v[i + 1].second -= mn;
    }
  }
  for (int i = (0); i < (int)(v.size()); i++) {
    ret += v[i].second;
  }
  cout << ret << endl;
  return 0;
}
