#include <bits/stdc++.h>
using namespace std;
string s;
int ans, fs, ft;
vector<int> v;
int main() {
  cin >> s;
  ans = s.size();
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'T' && (i == 0 || s[i - 1] == 'S')) v.push_back(i);
    if (s[i] == 'S' && (i == 0 || s[i - 1] == 'T')) v.push_back(i);
  }
  for (int i = 0; i < v.size() - 1; ++i) {
    if (s[v[i]] == 'S') {
      if (i + 2 >= v.size()) {
        ft = s.size() - v[i + 1];
      } else {
        ft = v[i + 2] - v[i + 1];
      }
      fs = v[i + 1] - v[i];
      ans -= min(fs, ft) * 2;
    }
  }
  cout << ans;
}
