#include <bits/stdc++.h>
using namespace std;
string s;
long long int mark[200005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s;
  long long int st = 0;
  while (st < s.length()) {
    if (st < s.length() - 1 && s[st] == 'S' && s[st + 1] == 'T') {
      mark[st] = 1;
      mark[st + 1] = 1;
      long long int pr = st - 1, nx = st + 2;
      while (pr >= 0 && nx < s.length()) {
        if (s[pr] != 'S' || s[nx] != 'T') break;
        mark[pr] = 1;
        mark[nx] = 1;
        pr--;
        nx++;
      }
      st = nx - 1;
    }
    st++;
  }
  long long int ct = 0;
  for (long long int i = 0; i <= s.length() - 1; ++i)
    if (!mark[i]) ct++;
  cout << ct;
  cout << '\n';
}
