#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int ans = s.length();
  int cnt[2] = {};
  int now = 0;
  if (s[0] == 'T') now = 1;
  for (int i = 0; i < s.length(); ++i) {
    int hoge = 0;
    if (s[i] == 'S') {
      hoge = 0;
    } else {
      hoge = 1;
    }
    if (now == hoge) {
      cnt[now]++;
    } else {
      if (now == 0) {
        now = 1;
        cnt[1]++;
      } else {
        ans -= min(cnt[0], cnt[1]) * 2;
        cnt[0] = 1;
        cnt[1] = 0;
        now = 0;
      }
    }
  }
  ans -= min(cnt[0], cnt[1]) * 2;
  cout << ans << endl;
  return 0;
}
