#include <bits/stdc++.h>
using namespace std;
int main() {
  {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  };
  string s;
  cin >> s;
  long long len = s.size();
  long long l = -1, r = -1;
  for (long long i = (long long)0; i <= (long long)len - 1; i++) {
    if (s[i] == 'S') {
      l = i;
      break;
    }
  }
  for (long long i = (long long)len - 1; i >= (long long)0; i--) {
    if (s[i] == 'T') {
      r = i;
      break;
    }
  }
  if (r == -1 || l == -1 || r < l)
    cout << 0 << endl;
  else {
    long long scnt = 1, tcnt = 1, cnt = 0;
    for (long long i = (long long)l + 1; i <= (long long)r; i++) {
      if (s[i] == 'S' && s[i - 1] == 'S')
        scnt++;
      else if (s[i] == 'T' && s[i - 1] == 'T')
        tcnt++;
      else if (s[i] == 'S' && s[i - 1] == 'T') {
        cnt += (min(scnt, tcnt) * 2);
        scnt = 1;
        tcnt = 1;
      }
    }
    cnt += (min(scnt, tcnt) * 2);
    cout << len - cnt << endl;
  }
  return 0;
}
