#include <bits/stdc++.h>
using namespace std;
vector<pair<char, int> > runlength(string str) {
  vector<pair<char, int> > ret;
  int cnt = 1;
  int n = (int)str.size();
  for (int i = 1; i < n; ++i) {
    if (str[i] == str[i - 1]) {
      cnt++;
    } else {
      ret.emplace_back(make_pair(str[i - 1], cnt));
      cnt = 1;
    }
  }
  ret.emplace_back(make_pair(str[n - 1], cnt));
  return ret;
}
int main() {
  string str;
  cin >> str;
  auto v = runlength(str);
  if (v[0].first == 'T') v.insert(v.begin(), {'S', 0});
  if (v[(int)v.size() - 1].first == 'S') v.insert(v.end(), {'T', 0});
  int cnt = 0;
  while (1) {
    int flg = 0;
    for (int i = 0; i < (int)v.size() - 1; i++) {
      if (v[i].first != 'S' || v[i + 1].first != 'T') continue;
      flg = 1;
      int tmp = (v[i].second < v[i + 1].second ? v[i].second : v[i + 1].second);
      if (tmp != 0) flg = 1;
      v[i].second -= tmp;
      v[i + 1].second -= tmp;
      if (v[i].second == 0) {
        v.erase(v.begin() + i);
        if (v[i].second == 0) v.erase(v.begin() + i);
      } else {
        if (v[i + 1].second == 0) v.erase(v.begin() + i + 1);
      }
      cnt += tmp;
    }
    if (flg == 0) break;
  }
  int ans = 0;
  for (int i = 0; i < (int)v.size(); ++i) ans += v[i].second;
  cout << ans << endl;
}
