#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  string str;
  ll s = 0, t = 0, i = 0, ans = 0;
  cin >> str;
  while (i < str.size()) {
    s = 0;
    t = 0;
    while (str[i] == 'S') s++, i++;
    while (str[i] == 'T') t++, i++;
    ans += min(s, t);
  }
  cout << str.size() - ans * 2 << endl;
  return 0;
}
