#include <bits/stdc++.h>
using namespace std;
long long const INF = 1LL << 60;
long long const MAX_N = 510000;
long long const MOD = 1000000007;
int main() {
  string X;
  cin >> X;
  vector<pair<char, long long>> pairs;
  long long s_cnt = 0;
  long long t_cnt = 0;
  if (X[0] == 'S')
    s_cnt++;
  else if (X[0] == 'T')
    t_cnt++;
  for (int i = 1; i < X.length(); i++) {
    if (X[i] == 'S') {
      if (X[i - 1] == X[i]) {
        s_cnt++;
      } else {
        pair<char, long long> p = make_pair('T', t_cnt);
        pairs.push_back(p);
        t_cnt = 0;
        s_cnt = 1;
      }
    } else if (X[i] == 'T') {
      if (X[i - 1] == X[i]) {
        t_cnt++;
      } else {
        pair<char, long long> p = make_pair('S', s_cnt);
        pairs.push_back(p);
        s_cnt = 0;
        t_cnt = 1;
      }
    }
  }
  if (X[X.length() - 1] == 'S') {
    pair<char, long long> p = make_pair('S', s_cnt);
    pairs.push_back(p);
  } else if (X[X.length() - 1] == 'T') {
    pair<char, long long> p = make_pair('T', t_cnt);
    pairs.push_back(p);
  }
  while (1) {
    long long cnt = 0;
    for (int i = 0; i < pairs.size() - 1; i++) {
      if (pairs[i].first == 'S' && pairs[i + 1].first == 'T') {
        long long p1 = pairs[i].second;
        long long p2 = pairs[i + 1].second;
        pairs[i].second -= min(p1, p2);
        pairs[i + 1].second -= min(p1, p2);
        cnt++;
      }
    }
    if (cnt == 0) break;
    vector<pair<char, long long>>::iterator it = pairs.begin();
    while (it != pairs.end()) {
      if ((*it).second == 0) {
        it = pairs.erase(it);
      } else
        it++;
    }
    if (pairs.size() == 0) {
      cout << "0" << endl;
      return 0;
    } else if (pairs.size() == 1) {
      cout << pairs[0].second << endl;
      return 0;
    }
    it = pairs.begin() + 1;
    while (it != pairs.end()) {
      if ((*(it - 1)).first == (*it).first) {
        (*(it - 1)).second += (*it).second;
        it = pairs.erase(it);
      } else
        it++;
    }
  }
  long long ans = 0;
  for (int i = 0; i < pairs.size(); i++) {
    ans += pairs[i].second;
  }
  cout << ans << endl;
  return 0;
}
