#include <bits/stdc++.h>
using namespace std;
template <typename T>
void DEBUG(T e) {
  if (true == false) return;
  std::cout << e << std::endl;
}
template <typename T>
void DEBUG(const std::vector<T>& v) {
  if (true == false) return;
  for (const auto& e : v) {
    std::cout << e << " ";
  }
  std::cout << std::endl;
}
template <typename T>
void DEBUG(const std::vector<std::vector<T> >& vv) {
  if (true == false) return;
  for (const auto& v : vv) {
    DEBUG(v);
  }
}
template <class T, class X>
void DEBUG(X d, T e) {
  if (true == false) return;
  std::cout << d << " ";
  DEBUG(e);
};
template <class T>
void corner(bool flg, T hoge) {
  if (flg) {
    cout << hoge << endl;
    exit(0);
  }
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b) {
  return a < b && (a = b, true);
}
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b) {
  return a > b && (a = b, true);
}
template <typename T>
using matrix = vector<vector<T> >;
void solve(void) {
  string str;
  cin >> str;
  long long D = 0;
  long long cnt_s = 0, cnt_t = 0;
  long long N = str.size();
  for (long long i = 0; i < str.size(); i++) {
    if (str[i] == 'S')
      cnt_s++;
    else if (str[i] == 'T')
      cnt_t++;
    if (i < N - 1) {
      if (str[i] == 'T' && str[i + 1] == 'S') {
        D += min(cnt_s, cnt_t) * 2;
        cnt_s = 0;
        cnt_t = 0;
      }
    }
  }
  D += min(cnt_s, cnt_t) * 2;
  cout << N - D << endl;
  return;
}
int32_t main(int32_t argc, const char* argv[]) {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  return 0;
}
