#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 123;
const int mod = 1e9 + 7;
const long long inf = 1e18 + 9;
inline void boost() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
}
char a[12345];
int prv[12345], nxt[12345], cnt;
int main() {
  boost();
  cin >> a + 1;
  int n = strlen(a + 1);
  for (int i = 1; i <= n; i++) prv[i] = i - 1, nxt[i] = i + 1;
  for (int i = 1; i <= n; i++) {
    if (a[i] != 'S' && a[i] != 'T') continue;
    if (a[prv[i]] == 'S' && a[i] == 'T') {
      a[prv[i]] = a[i] = '#';
      prv[i] = prv[prv[i]];
      prv[i + 1] = prv[i];
    }
  }
  for (int i = 1; i <= n; i++) cnt += (a[i] == '#');
  cout << n - cnt;
  return 0;
}
