#include <bits/stdc++.h>
using namespace std;
bool done[222222];
int main() {
  string S;
  cin >> S;
  int L = S.size();
  set<pair<int, int> > occ;
  for (int i = 0; i < L - 1; i++) {
    if (S[i] == 'S' && S[i + 1] == 'T') {
      occ.insert(make_pair(i, i + 1));
    }
  }
  for (int i = 0; i < L; i++) {
    done[i] = false;
  }
  while (!occ.empty()) {
    pair<int, int> top = *occ.begin();
    occ.erase(occ.begin());
    int u = top.first;
    int v = top.second;
    if (done[u] || done[v]) continue;
    done[u] = done[v] = true;
    if (u > 0 && !done[u - 1] && v < L - 1 && !done[v + 1] && S[u - 1] == 'S' &&
        S[v + 1] == 'T') {
      occ.insert(make_pair(u - 1, v + 1));
    }
  }
  int ans = 0;
  for (int i = 0; i < L; i++) ans += (int)(!done[i]);
  cout << ans << endl;
}
