#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int MOD = 1000000007;
const int INF = 1e9;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int ddx[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int ddy[8] = {0, 1, -1, 0, 1, -1, 1, -1};
int main() {
  string x;
  cin >> x;
  char now = 'S';
  int del = 0;
  int s = 0, t = 0;
  for (int i = 0; i < (int)(x.length()); i++) {
    if (now == x[i]) {
      if (now == 'S')
        s++;
      else
        t++;
    } else {
      if (x[i] == 'T') {
        now = 'T';
        t++;
      } else {
        now = 'S';
        del += 2 * min(s, t);
        s = 1, t = 0;
      }
    }
  }
  del += 2 * min(s, t);
  int ans = x.length() - del;
  cout << ans << endl;
}
