#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;
vector<int> bitSearch(int bit, int n) {
  vector<int> S;
  for (int i = 0; (i) < (int)(n); i++)
    if (bit & (1 << i)) S.push_back(i);
  return S;
}
int main() {
  string s;
  cin >> s;
  s.insert(0, "0");
  int res = 0, cnt = 0;
  int n = s.size();
  int dp[n + 1][2];
  for (int i = 0; (i) < (int)(n + 1); i++)
    for (int j = 0; (j) < (int)(2); j++) dp[i][j] = 1e9;
  for (int i = (int)(1); (i) <= (int)(n); i++) {
    if (s[i] == 'S') {
      if (dp[i - 1][1] != 1e9 && cnt > 0)
        cnt = 0;
      else
        cnt++;
      dp[i][0] = cnt;
    }
    if (s[i] == 'T') {
      if (cnt) res++;
      cnt = max(cnt - 1, 0);
      dp[i][1] = cnt;
    }
  }
  cout << n - res * 2 - 1;
}
