#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const long long INFL = 0x3f3f3f3f3f3f3f3f;
long long gcd(long long x, long long y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
long long lcm(long long x, long long y) {
  long long g = gcd(x, y);
  return x / g * y;
}
int main() {
  string s;
  cin >> s;
  int n = s.size();
  int ans = 0;
  int sumt = 0;
  for (long long i = 0; i < (n); i++) {
    if (i == 0 && s[i] != 'T') break;
    if (s[i] == 'T')
      sumt++;
    else
      break;
  }
  int sums = 0;
  for (long long i = 0; i < (n); i++) {
    if (i == 0 && s[n - 1 - i] != 'S') break;
    if (s[n - 1 - i] == 'S')
      sums++;
    else
      break;
  }
  int x = 0, y = 0;
  for (int i = sumt; i < n - sums; i++) {
    if (s[i] == 'S')
      x++;
    else
      y++;
  }
  ans = sumt + sums + abs(x - y);
  cout << ans << endl;
}
