#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;
}
string S, T;
signed main() {
  cin >> S;
  long long N = S.size();
  long long s = 0, t = 0;
  long long sum = 0;
  for (long long i = 0; i < (long long)(N - 1); i++) {
    if (S[i] == 'S' && S[i + 1] == 'S') {
      s++;
    } else if (S[i] == 'T' && S[i + 1] == 'T') {
      t++;
    } else if (S[i] == 'S' && S[i + 1] == 'T') {
      s++;
      t++;
    } else if (S[i] == 'T' && S[i + 1] == 'S') {
      sum += (((long long)(s) < (long long)(t)) ? (s) : (t)) * 2;
      s = 0;
      t = 0;
    }
    {} {} {} {} {}
  }
  {} {} {}
  if (s == t) {
    sum += s * 2;
  }
  {} {}
  cout << N - sum << endl;
  return 0;
}
