#include <bits/stdc++.h>
class _in {
  struct my_iterator {
    int it;
    const bool rev;
    explicit constexpr my_iterator(int it_, bool rev = false)
        : it(it_), rev(rev) {}
    constexpr int operator*() { return it; }
    constexpr bool operator!=(my_iterator& r) { return it != r.it; }
    void operator++() { rev ? --it : ++it; }
  };
  const my_iterator i, n;

 public:
  explicit constexpr _in(int n) : i(0), n(n) {}
  explicit constexpr _in(int i, int n) : i(i, n < i), n(n) {}
  constexpr const my_iterator& begin() { return i; }
  constexpr const my_iterator& end() { return n; }
};
using namespace std;
const int INF = 1e9;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int N = s.size();
  vector<int> a(N, 0);
  for (int i : _in(N)) {
    if (s[i] == 'T')
      a[i] = -1;
    else
      a[i] = 1;
  }
  for (int i : _in(N - 1)) a[i + 1] += a[i];
  int pre = 0;
  int sum = 0, h = INF, id = -INF;
  for (int i : _in(N)) {
    if (pre < a[i]) {
      if (id == -INF) {
        h = pre;
        id = i - 1;
      }
    } else if (id != -INF) {
      if (a[i] == h) {
        sum += i - id;
        id = -INF;
        h = INF;
      }
      if (i == N - 1 || a[i] < a[i + 1]) {
        sum += i - id;
        id = -INF;
        h = INF;
      }
    }
    pre = a[i];
  }
  cout << N - sum << endl;
  return 0;
}
