#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9 + 7;
const long long LINF = 1e18;
using namespace std;
int main() {
  string x;
  cin >> x;
  int n = x.size();
  vector<int> vec;
  char now = 'S';
  int cnt = 0;
  for (int i = 0; i < (int)(n); i++) {
    if (now != x[i]) {
      vec.push_back(cnt);
      cnt = 1;
      now = (now == 'S' ? 'T' : 'S');
    } else
      cnt++;
  }
  vec.push_back(cnt);
  if (vec.size() < 2) {
    cout << n << endl;
    return 0;
  }
  if (vec.size() % 2 == 1) vec.push_back(0);
  int ans = n;
  for (int i = 0; i < (int)(n / 2); i++) {
    ans -= min(vec[2 * i], vec[2 * i + 1]) * 2;
  }
  cout << ans << endl;
}
