#include <bits/stdc++.h>
using namespace std;
signed main() {
  string S;
  cin >> S;
  bool fg = 0;
  long long scnt = 0;
  long long tcnt = 0;
  long long ans = (long long)S.size();
  for (long long i = 0; i < S.size(); i++) {
    if (S.at(i) == 'S') {
      if (fg == 1) {
        ans -= min(tcnt, scnt) * 2;
        tcnt = 0;
        scnt = 1;
        fg = 0;
      } else {
        scnt++;
      }
    } else if (S.at(i) == 'T') {
      tcnt++;
      fg = 1;
    }
  }
  ans -= min(tcnt, scnt) * 2;
  cout << ans << endl;
}
