#include <bits/stdc++.h>
using namespace std;
const double Eps = (double)0.5;
const int M = 1e9 + 7;
const int N = 2e5 + 5;
const double PI = acos(-1.0);
char a[N];
int main() {
  cin >> a;
  int l = strlen(a);
  int i = 0;
  int j;
  int x;
  int y;
  int asr = 0;
  while (i < l) {
    for (j = i; j < l; j++) {
      if (a[j] == 'S') break;
    }
    x = 0;
    while (j < l && a[j] == 'S') {
      x++;
      j++;
    }
    y = 0;
    if (j == l) break;
    while (j < l && a[j] == 'T') {
      y++;
      j++;
    }
    asr += min(x, y) * 2;
    i = j;
  }
  cout << l - asr << endl;
  return 0;
}
