#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool smin(T &a, const T &b) {
  return b < a ? a = b, 1 : 0;
}
template <typename T>
inline bool smax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
string s;
long long n;
vector<long long> all;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  n = (long long)s.size();
  all.push_back(1);
  for (long long i = 1; i < n; ++i) {
    if (s[i] == s[i - 1])
      all.back()++;
    else
      all.push_back(1);
  }
  if (s[0] == 'T') {
    long long res = 0;
    for (long long i = 1; i < (long long)all.size(); i += 2) {
      if (i + 1 < (long long)all.size()) res += min(all[i], all[i + 1]);
    }
    cout << n - 2 * res << endl;
  } else {
    long long res = 0;
    for (long long i = 0; i < (long long)all.size(); i += 2) {
      if (i + 1 < (long long)all.size()) res += min(all[i], all[i + 1]);
    }
    cout << n - 2 * res << endl;
  }
}
