#include <bits/stdc++.h>
using namespace std;
template <class T>
T IN() {
  T d;
  cin >> d;
  return d;
}
long long gcd(long long a, long long b) { return (b > 0) ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
bool uruu(long long Y) {
  return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false);
}
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ;
  bool dbgF = true;
  string X;
  cin >> X;
  long long ans = X.length();
  long long Ssum = 0, Tsum = 0;
  int flg = 0;
  for (int i = (X.length() - 1); i >= (0); i--) {
    if (X[i] == 'T' && flg == 2) {
      ans -= min(Tsum, Ssum) * 2;
      Tsum = 0;
      Ssum = 0;
      flg = 0;
    }
    if (X[i] == 'T' && flg == 0) {
      flg = 1;
    } else if (X[i] == 'S' && flg == 1) {
      flg = 2;
    }
    if (X[i] == 'T' && flg == 1) {
      Tsum++;
    } else if (X[i] == 'S' && flg == 2) {
      Ssum++;
    }
    if (i == 0 && flg == 2) {
      ans -= min(Tsum, Ssum) * 2;
    }
  }
  cout << ans << endl;
  return 0;
}
