#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1e16;
const long double EPS = 1e-10;
const long double PI = 3.141592653589793;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
const pair<long long, long long> fd[] = {make_pair(1, 0), make_pair(-1, 0),
                                         make_pair(0, 1), make_pair(0, -1)};
signed main() {
  string x;
  cin >> x;
  long long ans = 0, cnt = 0;
  for (long long i = (0); i < (x.length()); i++) {
    if (x[i] == 'S') {
      if (i > 0 && x[i - 1] == 'T') {
        ans += cnt;
        cnt = 0;
      }
      cnt++;
    } else {
      if (cnt == 0)
        ans++;
      else
        cnt--;
    }
  }
  ans += cnt;
  cout << ans << endl;
}
