#include <bits/stdc++.h>
using namespace std;
const constexpr int INF = 1e9;
int A, B, C, D, E, F;
int a[200001];
string X;
struct Node {
  int from, to, cost;
};
void solve() {
  int cnt = 0;
  for (int i = 1; i < X.size() + 1; ++i) {
    if (X[i - 1] == 'S')
      a[i] = a[i - 1] + 1;
    else if (X[i - 1] == 'T')
      a[i] = a[i - 1] - 1;
  }
  for (int i = 1; i < 200001; ++i)
    if (a[i] < 0) cnt++;
  cout << cnt << endl;
}
int main() {
  cin >> X;
  solve();
  return 0;
}
