#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T>
void chmin(T &a, T b) {
  a = min(a, b);
}
template <typename T>
void chmax(T &a, T b) {
  a = max(a, b);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string x;
  cin >> x;
  vector<int> s, t;
  if (x[0] == 'T') s.push_back(0);
  int n = x.size(), same = 1;
  char bef = x[0];
  for (int i = 1; i < n; i++) {
    if (bef == x[i]) {
      same++;
    } else {
      if (x[i] == 'T')
        s.push_back(same);
      else
        t.push_back(same);
      same = 1;
    }
    bef = x[i];
  }
  if (x[n - 1] == 'S') {
    s.push_back(same);
    t.push_back(0);
  } else {
    t.push_back(same);
  }
  ll ans = 0;
  for (int i = 0; i < s.size(); i++) {
    ans += abs(s[i] - t[i]);
  }
  cout << ans << endl;
}
