#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e+18 + 1;
const long long MOD = 1000000007LL;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main() {
  string s;
  cin >> s;
  long long counts = 0;
  long long countt = 0;
  long long ans = 0;
  for (long long i = 0; i < (long long)(s.size()); i++) {
    if (i >= 1 && s[i - 1] == 'T' && s[i] == 'S') {
      ans += min(counts, countt) * 2;
      counts = 0;
      countt = 0;
    }
    if (s[i] == 'S') {
      counts++;
    }
    if (s[i] == 'T') {
      countt++;
    }
    if (i == s.size() - 1) {
      ans += min(counts, countt) * 2;
    }
  }
  cout << s.size() - ans << endl;
}
