#include <bits/stdc++.h>
using namespace std;
string s;
int cnt, a, b;
int main() {
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'S') a++;
    if (b != 0 and s[i] == 'T') b++;
    if (a + b == 2) cnt++, a = 0, b = 0;
  }
  cout << s.size() - 2 * cnt << endl;
}
