#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1000000007;
int main() {
  string ST;
  cin >> ST;
  int ans = 0;
  char now = 'S';
  int count = 0, s = 0;
  for (int i = 0; i < ST.size(); i++) {
    if (ST.at(i) == now)
      count++;
    else {
      if (now == 'S') {
        s = count;
        count = 1;
        now = 'T';
      } else {
        ans += abs(count - s);
        count = 1;
        now = 'S';
      }
    }
  }
  if (ST.at(ST.size() - 1) == 'S')
    ans += count;
  else
    ans += abs(s - count);
  cout << ans << endl;
  return 0;
}
