#include <bits/stdc++.h>
using namespace std;
int main() {
  char chr, chr0;
  int ans = 0, count_s = 0;
  while (cin >> chr) {
    switch (chr) {
      case 'S':
        if (chr0 == 'T') count_s = 0;
        ans++;
        count_s++;
        break;
      case 'T':
        ans++;
        if (count_s > 0) {
          ans -= 2;
          count_s--;
        }
        break;
      default:
        break;
    }
    chr0 = chr;
  }
  cout << ans << endl;
}
