#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  return a % b == 0 ? b : gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
  return (a / gcd(a, b)) * b;
}
int main() {
  string s;
  cin >> s;
  int n = s.size(), ans = 0, scount = 0, tcount = 0;
  stack<char> stk;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'S') {
      stk.push(s[i]);
    } else if (s[i] == 'T') {
      if (stk.top() == 'S')
        stk.pop();
      else if (stk.empty() || stk.top() == 'T')
        ans++;
    }
  }
  cout << ans;
}
