#include <bits/stdc++.h>
using namespace std;
char s[200005];
int n;
int solve(int i, int j) {
  if (j == n) return 0;
  if (s[i] == 'S' && s[j] == 'T') {
    if (i > 0) {
      return solve(i - 1, j + 1) + 2;
    }
    return solve(j + 1, j + 2) + 2;
  }
  return solve(i + 1, j + 1);
}
int main() {
  gets(s);
  n = strlen(s);
  cout << (n - solve(0, 1)) << endl;
  return 0;
}
