#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = 1000000000;
int main() {
  string x;
  cin >> x;
  bool s = false, t = false;
  int sum = 0;
  for (long long int i = (0); i < (x.size()); i++) {
    if (x[i] == 'S') s = true;
    if (x[i] == 'T') t = true;
    if (s && t && x[i] == 'T') {
      s = false;
      t = false;
      sum += 2;
      x[i] = 'x';
      x[i - 1] = 'x';
      i -= 2;
    }
  }
  int ans = x.size() - sum;
  cout << ans << endl;
  return 0;
}
