#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long to, cost;
};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007;
long long mpow(long long a, long long n, long long mod = MOD) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
void yn(bool j) {
  cout << (j ? "Yes" : "No") << endl;
  return;
}
template <class Head>
void pt(Head&& head) {
  cout << head << endl;
  return;
}
template <class Head, class... Tail>
void pt(Head&& head, Tail&&... tail) {
  cout << head << " ";
  pt(forward<Tail>(tail)...);
}
template <class T>
void debug(T v) {
  for (int i = 0; i < (v.size()); ++i) cout << v[i] << " ";
  cout << endl;
}
template <class T>
void debug2(T v) {
  for (int i = 0; i < (v.size()); ++i) {
    for (int j = 0; j < (v[i].size()); ++j) cout << v[i][j] << " ";
    cout << endl;
  }
}
template <class T1, class T2>
long long bcount(T1 v, T2 a) {
  return (long long)distance((v).begin(),
                             upper_bound((v).begin(), (v).end(), a)) -
         (long long)distance((v).begin(),
                             lower_bound((v).begin(), (v).end(), a));
}
template <class T1, class T2>
inline bool chmin(T1& a, T2 b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T1, class T2>
inline bool chmax(T1& a, T2 b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  string S;
  cin >> S;
  long long N = S.size();
  vector<long long> dp_s(N, 0);
  vector<long long> dp_t(N, 0);
  if (S[0] == 'S') {
    dp_s[0] = 1;
    dp_t[0] = 0;
  }
  for (int i = 0; i < (N - 1); ++i) {
    if (S[i] == 'S' && S[i + 1] == 'S') {
      dp_s[i + 1] = dp_s[i] + 1;
      dp_t[i + 1] = 0;
    } else if (S[i] == 'S' && S[i + 1] == 'T') {
      dp_s[i + 1] = dp_s[i];
      dp_t[i + 1] = 1;
    } else if (S[i] == 'T' && S[i + 1] == 'S') {
      dp_s[i + 1] = 1;
      dp_t[i + 1] = 0;
    } else if (S[i] == 'T' && S[i + 1] == 'T') {
      dp_s[i + 1] = dp_s[i];
      dp_t[i + 1] = min(dp_s[i], dp_t[i] + 1);
    }
  }
  dp_t.push_back(0);
  reverse((dp_t).begin(), (dp_t).end());
  long long ans = 0;
  for (int i = 0; i < (N); ++i) {
    if (dp_t[i + 1] > dp_t[i]) ans += dp_t[i + 1];
  }
  ans = N - ans * 2;
  pt(ans);
}
