#include <bits/stdc++.h>
using namespace std;
int main() {
  string x;
  int ans, c, i, k, l, n, m, s[200000], t[200000];
  cin >> x;
  n = x.size();
  x.push_back('T');
  k = 0;
  l = 0;
  for (i = 0; i < n; i++) {
    if (x[i] == 'S') {
      c = i;
      break;
    }
  }
  for (i = c; i < n; i++) {
    if (x[i] == 'S') {
      s[k] += 1;
      if (x[i + 1] == 'T') {
        k++;
      }
    }
    if (x[i] == 'T') {
      t[l] += 1;
      if (x[i + 1] == 'S') {
        l++;
      }
    }
  }
  for (i = 0; i < k; i++) {
    m = t[i] - s[i];
    if (m > 0) {
      ans += m;
    } else {
      s[i + 1] -= m;
    }
  }
  cout << (ans + c) * 2 << endl;
}
