#include <bits/stdc++.h>
using namespace std;
char c[200001];
int cc[200001];
int main() {
  cin >> c;
  int length = strlen(c);
  for (int i = 0; i < length; i++) {
    if (!cc[i] && c[i] == 'S') {
      for (int y = i + 1; y < length; y++) {
        if (!cc[y] && c[y] != 'T') {
          break;
        } else if (!cc[y] && c[i] == 'S' && c[y] == 'T') {
          cc[i] = 1;
          cc[y] = 1;
          for (int n = 1, m = 1; n <= i && y + m < length;) {
            while (n <= i && cc[i - n]) {
              if (cc[i - n]) n++;
            }
            while (y + m < length && cc[y + m])
              if (cc[y + m]) m++;
            if (!cc[i - n] && !cc[y + n] && c[i - n] == 'S' &&
                c[y + n] == 'T') {
              cc[i - n] = 1;
              cc[y + n] = 1;
            } else {
              i = y + n;
              break;
            }
          }
          break;
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < length; i++) {
    if (!cc[i]) {
      ans++;
    }
  }
  cout << ans << endl;
}
