#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long MOD = 1e9 + 7;
long long gcd(long long x, long long y) {
  if (y == 0) return 0;
  return gcd(y, x % y);
}
int dis2(int x1, int y1, int x2, int y2) {
  return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}
int main() {
  string x;
  cin >> x;
  int rm = 0, s = 0, t = 0;
  for (int i = 0; i < (int)x.size(); i++) {
    if (x[i] == 'S')
      s++;
    else
      t++;
    if (i == (int)x.size() - 1 || (x[i] == 'T' && x[i + 1] == 'S')) {
      rm += min(s, t) * 2;
      s = 0;
      t = 0;
    }
  }
  cout << (int)x.size() - rm << endl;
  return 0;
}
