#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
  string x;
  while (getline(cin, x)) {
    int length = 0;
    int s = -1;
    unsigned int count = 0;
    for (unsigned int i = 0; i < x.size(); ++i) {
      if (s < 0) {
        if (x[i] == 'S') {
          s = i;
        }
      } else {
        if (x[i] == 'T') {
          length -= 2;
          ++count;
          if (i >= 2) {
            unsigned int counter = 0;
            for (unsigned int j = i - 1; j >= 0; --j) {
              if (x[j] == 'T') {
                s = -1;
                break;
              } else {
                ++counter;
                if (counter > count) {
                  s = j;
                  break;
                }
              }
            }
          } else {
            s = -1;
          }
        }
      }
      ++length;
    }
    cout << length << endl;
  }
  return 0;
}
