#include <bits/stdc++.h>
using namespace std;
signed main() {
  string s;
  cin >> s;
  long long ans = 0;
  long long cs = 0, ct = 0;
  bool f = false;
  s += 'S';
  for (long long i = 0; i < s.size(); i++) {
    if (!f && s[i] == 'S') {
      ans += min(cs, ct);
      f = true;
      cs = 1;
      ct = 0;
    } else if (s[i] == 'S') {
      cs++;
    } else if (f && s[i] == 'T') {
      f = false;
      ct = 1;
    } else if (s[i] == 'T') {
      ct++;
    }
  }
  ans = (long long)s.size() - 2 * ans - 1;
  cout << ans << endl;
}
