#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
  if (b == 0) return a;
  return (a / gcd(a, b)) * b;
}
vector<int> divnum(long long num) {
  int dig;
  vector<int> p;
  while (num) {
    dig = num % 10;
    p.push_back(dig);
    num /= 10;
  }
  return p;
}
int digiter(long long num) {
  int dig;
  vector<int> p;
  while (num) {
    dig = num % 10;
    p.push_back(dig);
    num /= 10;
  }
  return p.size();
}
vector<int> convertstring(string s) {
  vector<int> d;
  long long n = s.size();
  for (long long i = 0; i < n; i++) {
    d.push_back(s[i] - '0');
  }
  return d;
}
map<long long, int> prime_factor(long long n) {
  map<long long, int> ret;
  for (long long i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
vector<long long> Enumeration(long long n) {
  vector<long long> res;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i != 0) continue;
    res.push_back(i);
    if (i * i != n) res.push_back(n / i);
  }
  return res;
}
long long myPow(long long x, long long n, long long m) {
  if (n == 0) return 1;
  if (n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}
std::vector<int> Eratosthenes(const int N) {
  std::vector<bool> is_prime(N + 1);
  for (int i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  std::vector<int> pair<long long, long long>;
  for (int i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (int j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      pair<long long, long long>.emplace_back(i);
    }
  }
  return pair<long long, long long>;
}
const long long mod = (1e9 + 7);
struct mint {
  long long x;
  mint(long long x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
  explicit operator int() const { return x; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
struct combination {
  vector<mint> fact, ifact;
  combination(long long n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (long long i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (long long i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(long long n, long long k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
} comb(1000005);
mint f(long long n, long long k) {
  if (n < 0) return 0;
  mint res = comb(n, k);
  res *= comb.fact[k];
  return res;
}
struct SegmentTree {
 private:
  int n;
  vector<int> node;

 public:
  SegmentTree(vector<int> v) {
    int sz = v.size();
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1, (1e9));
    for (int i = 0; i < sz; i++) node[i + n - 1] = v[i];
    for (int i = n - 2; i >= 0; i--)
      node[i] = min(node[2 * i + 1], node[2 * i + 2]);
  }
  void update(int x, int val) {
    x += (n - 1);
    node[x] = val;
    while (x > 0) {
      x = (x - 1) / 2;
      node[x] = min(node[2 * x + 1], node[2 * x + 2]);
    }
  }
  int getmin(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (r <= a || b <= l) return (1e9);
    if (a <= l && r <= b) return node[k];
    int vl = getmin(a, b, 2 * k + 1, l, (l + r) / 2);
    int vr = getmin(a, b, 2 * k + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
};
struct BIT {
 private:
  vector<int> bit;
  int N;

 public:
  BIT(int size) {
    N = size;
    bit.resize(N + 1);
  }
  void add(int a, int w) {
    for (int x = a; x <= N; x += x & -x) bit[x] += w;
  }
  int sum(int a) {
    int ret = 0;
    for (int x = a; x > 0; x -= x & -x) ret += bit[x];
    return ret;
  }
};
int par[int(0x7ffffff)];
int Rank[int(0x7ffffff)];
string S;
int32_t main() {
  cin >> S;
  int N = S.size();
  int l = -1;
  int ans = 0;
  for (long long i = 0; i < N; i++) {
    if (S[i] == 'S' && l == -1) l = i;
    if (S[i] == 'T' && l != -1) {
      int cnt = 0;
      int d = i;
      while (i < N) {
        if (S[i] == 'T')
          cnt++;
        else
          break;
        i++;
      }
      ans += min(d - l, cnt) * 2;
      l = -1;
      --i;
    }
  }
  cout << N - ans << endl;
}
