#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, cnts = 0;
  long long n = x.length();
  for (long long i = (0); i < (n); i++) {
    if (x[i] == 'S') {
      cnts++;
    } else {
      if (cnts == 0)
        ans++;
      else
        cnt++;
    }
  }
  for (long long i = n - 1; i >= 0; i--) {
    if (x[i] == 'T') break;
    ans++;
    cnts--;
  }
  ans += abs(cnt - cnts);
  cout << ans << endl;
}
