#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  vector<int> v;
  int len = 1;
  for (int(i) = (1); (i) < (int)(n); ++(i)) {
    if (s[i] == s[i - 1])
      len++;
    else {
      v.push_back(len);
      len = 1;
    }
  }
  v.push_back(len);
  int cnt = 0;
  int from = (s[0] == 'T' ? 1 : 0);
  for (int i = from; i < (int)v.size(); i += 2) {
    if (i + 1 == (int)v.size()) break;
    cnt += min(v[i], v[i + 1]) * 2;
  }
  cout << n - cnt << endl;
  return 0;
}
