#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long double PI = acos(-1);
const long double EPS = 0.0000000001;
int main() {
  string s;
  cin >> s;
  int ans = s.size(), tc = 0, sc = 0;
  for (int i = 0; i < s.size(); i++) {
    if (tc == 0 && s[i] == 'S')
      sc += 1;
    else if (sc > 0 && s[i] == 'T')
      tc += 1;
    else if (s[i] == 'S') {
      ans -= min(sc, tc) * 2;
      sc = 1;
      tc = 0;
    }
  }
  if (sc > 0 && tc > 0) ans -= min(sc, tc) * 2;
  cout << ans << endl;
}
