#include <bits/stdc++.h>
static const long long MOD = 1000000007;
static const long long INF = 1000000000000000000LL;
using namespace std;
int main() {
  string s;
  cin >> s;
  long long scnt = 0;
  long long tcnt = 0;
  long long res = 0;
  char cur = 'S';
  for (long long i = 0; i < (s.size()); i++) {
    if (s[i] == cur) {
      if (cur == 'S') {
        ++scnt;
      } else {
        ++tcnt;
      }
    } else {
      if (cur == 'S') {
        cur = 'T';
        tcnt = 1;
      } else {
        res += abs(tcnt - scnt);
        cur = 'S';
        scnt = 1;
        tcnt = 0;
      }
    }
  }
  res += abs(tcnt - scnt);
  cout << res << endl;
  return 0;
}
