#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 1;
const long long MOD = 1e9 + 7;
const long double PI = 3.14159265358979323846264338;
long long fast_ex(long long a, long long n, long long m) {
  if (n == 0) return 1;
  if (n == 1) return a;
  long long x = 1;
  x *= fast_ex(a, n / 2, m);
  x %= m;
  x *= x;
  x %= m;
  if (n % 2) x *= a;
  x %= m;
  return x;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string second;
  cin >> second;
  long long n = second.size();
  long long ans = n;
  long long i = 0;
  while (i < n) {
    if (second[i] == 'S' && second[i + 1] == 'T') {
      long long j = i - 1;
      long long k = i + 2;
      ans -= 2;
      while (j > -1 && k < n) {
        if (second[j] == 'S' && second[k] == 'T') {
          j--;
          k++;
          ans -= 2;
        } else {
          i = k - 1;
          break;
        }
      }
    }
    i++;
  }
  cout << ans;
  return 0;
}
