#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string x;
  cin >> x;
  int j = x.size() / 2 - 1;
  int count[j];
  memset(count, 0, sizeof(count));
  int tmp = 0;
  for (int i = x.size() - 1; i >= 0; i--) {
    if (x[i] == 'T')
      tmp++;
    else {
      count[j] = tmp;
      j--;
    }
  }
  j = x.size() / 2;
  int rsl = 0;
  int array[x.size()];
  memset(array, 0, sizeof(array));
  for (int i = (int)0; i < (int)j; i++) {
    array[count[i]]++;
  }
  for (int i = (int)0; i < (int)x.size(); i++) {
    rsl += min(array[i], i);
  }
  cout << x.size() - 2 * rsl << endl;
}
