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