#include <bits/stdc++.h>
using namespace std;
template <class A>
void pr(A a) {
  cout << (a) << endl;
}
template <class A, class B>
void pr(A a, B b) {
  cout << a << " ";
  pr(b);
}
template <class A, class B, class C>
void pr(A a, B b, C c) {
  cout << a << " ";
  pr(b, c);
}
template <class A, class B, class C, class D>
void pr(A a, B b, C c, D d) {
  cout << a << " ";
  pr(b, c, d);
}
template <class T>
inline bool chmin(T& a, T b) {
  return a > b ? a = b, true : false;
}
template <class T>
inline bool chmax(T& a, T b) {
  return a < b ? a = b, true : false;
}
int main(void) {
  string X;
  cin >> X;
  vector<int> x;
  int prev = 0;
  for (int i = 0; i < int(X.length() - 1); ++i) {
    if (X[i] != X[i + 1]) {
      x.push_back(i - prev + 1);
      prev = i + 1;
    }
  }
  x.push_back(X.length() - prev);
  int ans = X.length();
  for (int i = (X[0] == 'T') ? 1 : 0; i < x.size(); i += 2) {
    ans -= min(x[i], x[i + 1]) * 2;
  }
  pr(ans);
}
