#include <bits/stdc++.h>
using namespace std;
bool debug = false;
int buf = -1;
int peek() {
  if (buf == -1)
    return buf = getchar();
  else
    return buf;
}
void pop() { buf = -1; }
int main() {
  int a = 0, b = 0, c = 0, d = 0;
  for (;;) {
    int ch = peek();
    if (ch == EOF) goto end;
    if (ch == 'S') break;
    a++;
    pop();
  }
  for (;;) {
    int s = 0, t = 0;
    for (;;) {
      int ch = peek();
      if (ch == EOF) {
        d = s;
        goto end;
      }
      if (ch == 'T') break;
      s++;
      pop();
    }
    for (;;) {
      int ch = peek();
      if (ch != 'T') break;
      t++;
      pop();
    }
    b += s;
    c += t;
  }
end:
  cout << a + abs(b - c) + d << endl;
  return 0;
}
