#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int ans = s.size();
  int now = 0;
  string next = "ST";
  int tmp = 0;
  vector<int> num;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == next[now])
      tmp++;
    else {
      num.push_back(tmp);
      now ^= 1;
      tmp = 1;
    }
  }
  num.push_back(tmp);
  for (int i = 0; i < num.size(); i += 2) {
    if (i == num.size() - 1) break;
    ans -= 2 * min(num[i], num[i + 1]);
  }
  cout << ans << endl;
}
