#include <bits/stdc++.h>
using namespace std;
string str;
int main() {
  cin >> str;
  int len = str.size();
  int ans = 1;
  while (1) {
    int i = 0;
    int num1 = 0;
    int num2 = 0;
    int pos = 0;
    int len = str.size();
    while (i <= len - 2) {
      if (str[i] == 'S') num1++;
      if (str[i] == 'T') num2++;
      if (str[i] == 'S') {
        if (str[i + 1] == 'T') {
          pos = i;
          str.erase(pos, 2);
          break;
        }
      }
      if (num1 >= len / 2 || num2 >= len / 2) {
        ans = 0;
        break;
      }
      i++;
    }
    if (ans == 0 || str.size() == 0) break;
  }
  cout << str.size() << endl;
  return 0;
}
