#include <bits/stdc++.h>
using namespace std;
long long llmax = LLONG_MAX;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
vector<int> d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void neg() { cout << -1 << endl; }
void mysort(vector<string> &a) { sort(a.begin(), a.end()); }
int main() {
  string x;
  cin >> x;
  long long n = x.size(), cnt = 0, s = 0, t = 0;
  if (x[0] == 'S')
    s++;
  else
    t++;
  for (long long i = 1; i < n; i++) {
    if (t == 0 && x[i] == 'S')
      s++;
    else if (x[i] == 'S') {
      cnt += max(s - t, t - s);
      s = 1;
      t = 0;
    } else if (s == 0 && x[i] == 'T')
      cnt++;
    else if (x[i] == 'T')
      t++;
  }
  cnt += max(s - t, t - s);
  cout << cnt << endl;
}
