#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long long int MAX_N = 500010;
const long long int INF = 999999999999;
int main() {
  string x;
  cin >> x;
  int s = 0;
  int t = 0;
  int ans = 0;
  for (char c : x) {
    if (c == 'S') {
      if (t > 0) {
        ans += min(s, t);
        t = s = 0;
      }
      s++;
    } else {
      t++;
    }
  }
  if (x.back() == 'T') ans += min(s, t);
  cout << x.length() - 2 * ans << endl;
}
