#include <bits/stdc++.h>
using namespace std;
bool f[200005] = {0};
int main() {
  memset(f, 0, sizeof(f));
  string s;
  cin >> s;
  int l, r;
  for (int i = 0; i < s.size() - 1; i++) {
    if (!f[i] && !f[i + 1] && s[i] == 'S' && s[i + 1] == 'T') {
      f[i] = 1, f[i + 1] = 1;
      l = i, r = i + 1;
      while (l >= 0) {
        if (f[l - 1])
          l--;
        else
          break;
      }
      while (r < s.size()) {
        if (f[r + 1])
          r++;
        else
          break;
      }
      while (l >= 0 && r < s.size()) {
        if (s[l] == 'S' && s[r] == 'T') {
          f[l] = 1, f[r] = 1;
          l--;
          r++;
        } else
          break;
      }
    }
  }
  int count = 0;
  for (int i = 0; i < s.size(); i++) {
    if (!f[i]) count++;
  }
  cout << count << endl;
  return 0;
}
