#include <bits/stdc++.h>
using namespace std;
template <typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;
using PII = pair<int_fast32_t, int_fast32_t>;
template <class T>
using maxheap = std::priority_queue<T>;
template <class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL << 62) - 1;
constexpr int inf = (1 << 30) - 1;
const int mod = 1000000007;
signed main() {
  int START_TIME = clock();
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string x;
  cin >> x;
  i32 ans = x.size(), n = x.size();
  vi st(n);
  for (i32 i = 0; i < n - 1; ++i) {
    if (x[i] == 'S' && x[i + 1] == 'T') {
      i32 lidx = i, ridx = i + 1;
      st[i] = st[i + 1] = 1;
      while (1) {
        --lidx, ++ridx;
        if (x[lidx] == 'S' && x[ridx] == 'T')
          st[lidx] = st[ridx] = 1;
        else
          break;
        if (!(0 <= lidx && ridx < n)) break;
      }
    }
  }
  for (int i = 0; i < ((int)(n)); i++)
    if (st[i]) --ans;
  cout << ans << '\n';
}
