#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int ans = 0, cur = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'T') {
      int len = 0;
      while (i < s.size() && s[i] == 'T') {
        i++;
        len++;
      }
      ans += max(cur, len) - min(cur, len);
      cur -= min(cur, len);
      i--;
    } else {
      while (i < s.size() && s[i] == 'S') {
        i++;
        cur++;
      }
      i--;
    }
  }
  ans += cur;
  cout << ans;
  return 0;
}
