#include <bits/stdc++.h>
using namespace std;
const long long linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  for (auto& x : vec) is >> x;
  return is;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  for (long long i = 0; i < (vec.size()); i++) {
    if (i) os << " ";
    os << vec[i];
  }
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<vector<T>>& vec) {
  for (long long i = 0; i < (vec.size()); i++) {
    if (i) os << endl;
    os << vec[i];
  }
  return os;
}
vector<pair<char, int>> lanlength(string s) {
  char prev = '\0';
  int cnt = 0;
  vector<pair<char, int>> res;
  for (long long i = 0; i < (s.size() + 1); i++) {
    if (i == s.size() || s[i] != prev) {
      if (prev != '\0') {
        res.push_back({prev, cnt});
      }
      prev = s[i];
      cnt = 1;
    } else {
      ++cnt;
    }
  }
  return res;
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  string s;
  cin >> s;
  vector<pair<char, int>> v = lanlength(s);
  int ans = 0;
  for (long long i = 0; i < ((int)v.size() - 1); i++) {
    if (v[i].first == 'S' && v[i + 1].first == 'T') {
      ans += min(v[i].second, v[i + 1].second);
    }
  }
  cout << (int)s.size() - ans * 2 << endl;
}
