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