#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long to, cost;
};
const long long INF = 100000000000000000;
const long long INF2 = 9223372036854775807;
const long long MOD = 1000000007;
long long ceil2(long long a, long long b) {
  if (a % b == 0) {
    return a / b;
  } else {
    return a / b + 1;
  }
}
long long pow2(long long a, long long b) {
  long long r = 1;
  for (long long i = 1; i <= b; i++) {
    r *= a;
  }
  return r;
}
long long Log2(long long a) {
  long long t = 0;
  while (1) {
    if (a == 0 || a == 1) {
      break;
    }
    a /= 2;
    t++;
  }
  return t;
}
signed main() {
  string S;
  cin >> S;
  long long N = S.size();
  bool flag = false;
  long long cnt = 0, cnt2 = 0;
  long long mode = 0;
  long long M = 0;
  if (S[0] == 'S') {
    cnt++;
  }
  for (long long i = 1; i < N; i++) {
    if (S[i - 1] == 'S' && S[i] == 'S') {
      cnt++;
    } else if (S[i - 1] == 'S' && S[i] == 'T') {
      cnt2 = 1;
    } else if (S[i - 1] == 'T' && S[i] == 'T') {
      cnt2++;
    } else {
      M += (((long long)(cnt) < (long long)(cnt2)) ? (cnt) : (cnt2));
      cnt = 1;
      cnt2 = 0;
    }
  }
  {} {} {} {} {}
  M += (((long long)(cnt) < (long long)(cnt2)) ? (cnt) : (cnt2));
  cout << N - M * 2 << endl;
  return 0;
}
