#include <bits/stdc++.h>
using namespace std;
const unsigned long long mod = 1e9 + 7;
template <typename T>
void vprint(T &v) {
  for (int i = 0; i < (int)v.size(); ++i) {
    cout << v[i] << " ";
  }
  cout << endl;
}
int main() {
  string X;
  cin >> X;
  long long i = 0;
  long long N = X.size();
  long long res = N;
  while (X[i] == 'T') {
    i++;
    if (i == N) {
      cout << N << endl;
      return 0;
    }
  }
  vector<long long> lons;
  long long lon = 1;
  while (1) {
    if (i == N - 1) {
      lons.push_back(lon);
      break;
    }
    if (X[i] != X[i + 1]) {
      lons.push_back(lon);
      lon = 1;
    } else {
      lon++;
    }
    i++;
  }
  for (int i = 0; i < (int)lons.size() / 2; ++i) {
    res -= 2 * min(lons[2 * i], lons[2 * i + 1]);
  }
  cout << res << endl;
  return 0;
}
