#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (ll i = (0), __last_i = (v.size()); i < __last_i; i++) {
    if (i) os << " ";
    os << v[i];
  }
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
  for (ll i = (0), __last_i = (v.size()); i < __last_i; i++) {
    if (i) os << endl;
    os << v[i];
  }
  return os;
}
const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
int main() {
  string s;
  ll ans = 0;
  cin >> s;
  ll sc = 0;
  ll tc = 0;
  for (ll i = (0), __last_i = (s.size()); i < __last_i; i++) {
    if (i != s.size() - 1 && s[i] == 'T' && s[i + 1] == 'S') {
      tc++;
      ans += min(sc, tc) * 2;
      sc = 0;
      tc = 0;
    } else if (s[i] == 'S') {
      sc++;
    } else if (s[i] == 'T') {
      tc++;
    }
  }
  ans += min(sc, tc) * 2;
  cout << s.size() - ans << endl;
}
