#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
int main() {
  string s;
  cin >> s;
  int n = s.size() - 1;
  int ans = 0;
  bool same = true;
  int now = 1;
  vector<int> can;
  bool all = true;
  for (long long int i = 0; i < n; i++) {
    if (s[i] == s[i + 1] && same) {
      now++;
    } else if (s[i] == s[i + 1]) {
      now++;
      same = true;
    } else {
      all = false;
      can.push_back(now);
      now = 1;
    }
  }
  can.push_back(now);
  bool t = false;
  if (s[0] == 'T') t = true;
  if (t) {
    n = can.size();
    for (int i = 1; i < n - 1; i += 2) {
      ans += min(can[i], can[i + 1]);
    }
  } else {
    n = can.size();
    for (int i = 0; i < n - 1; i += 2) {
      ans += min(can[i], can[i + 1]);
    }
  }
  cout << s.size() - ans * 2 << endl;
}
