#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 100;
string s;
int a[MAXN];
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> s;
  int ans = 0;
  for (int i = 0; i < s.size() - 1; ++i) {
    if (s[i] == 'S' && s[i + 1] == 'T') {
      ans++;
      if (a[i] == -1) {
        continue;
      }
      int j = i - a[i] - 1;
      if (s[i + 2] == 'T' && s[j] == 'S') {
        ans++;
        a[i + 1] = a[i] + 2;
      } else {
        a[i + 1] = a[i] + 1;
      }
      i++;
    }
  }
  cout << s.size() - (ans * 2);
  return 0;
}
