#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 100;
string s;
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> s;
  long long ans = 0;
  while (1) {
    if (s.size() == 0) {
      break;
    }
    vector<int> pos;
    for (int i = 0; i < s.size() - 1; ++i) {
      if (s[i] == 'S' && s[i + 1] == 'T') {
        pos.push_back(i);
      }
    }
    if (pos.size() == 0) {
      break;
    }
    int ct = 0;
    int len = 0;
    for (auto to : pos) {
      ct++;
      to -= len;
      len = 2;
      long long last = to;
      if (to != 0) {
        long long l = to;
        long long r = to + 1;
        while (l != 0 || r != s.size() - 1) {
          l--;
          r++;
          if (s[l] == 'S' && s[r] == 'T') {
            len += 2;
            last = l;
          } else {
            break;
          }
        }
      }
      s.erase(last, len);
    }
  }
  cout << s.size();
  return 0;
}
