#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
  string S;
  cin >> S;
  int i = 0;
  long long ans = 0;
  while (i < S.size()) {
    long long Snum = 0;
    long long Tnum = 0;
    while (i < S.size() && S[i] == 'S') {
      i++;
      Snum++;
    }
    while (i < S.size() && S[i] == 'T') {
      i++;
      Tnum++;
    }
    ans += 2 * min(Snum, Tnum);
  }
  cout << S.size() - ans << endl;
}
