#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7ffffff;
const int mod = 1000000007;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  int ans = 0;
  vector<int> res(n);
  for (int i = 0; i < (n - 1); ++i) {
    if (s.substr(i, 2) == "ST")
      ans++;
    else {
      if (s[i] == 'S') res[i]++;
    }
    res[i + 1] += res[i];
  }
  vector<int> res2(n);
  reverse((s).begin(), (s).end());
  for (int i = 0; i < (n - 1); ++i) {
    if (s.substr(i, 2) == "TS")
      ;
    else {
      if (s[i] == 'T') res2[i]++;
    }
    res2[i + 1] += res2[i];
  }
  reverse((res2).begin(), (res2).end());
  int sol = 0;
  for (int i = 0; i < (n); ++i) {
    sol = max(sol, min(res[i], res2[i]));
  }
  ans += sol;
  cout << n - ans * 2 << endl;
  return 0;
}
