#include <bits/stdc++.h>
using namespace std;
int main(void) {
  string x;
  cin >> x;
  int ans = x.size();
  int bef = 0;
  bool flag = true;
  int now = 0;
  while (flag == true && x.size() >= 1) {
    flag = false;
    for (int i = 0; i < (x.size() - 1); i++) {
      if (x[i] == 'S' && x[i + 1] == 'T') {
        flag = true;
        int a = i;
        int b = i + 1;
        while (x[a] == 'S' && x[b] == 'T' && a >= 0 && b <= x.size() - 1) {
          --a;
          ++b;
        }
        string tmp = " ";
        now++;
        if (a >= 0) tmp += x.substr(0, a + 1);
        if (b <= x.size() - 1) tmp += x.substr(b, x.size() - b);
        x = tmp;
      }
    }
  }
  cout << x.size() - now << endl;
  return 0;
}
