#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7ffffff;
const int mod = 1000000007;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  vector<int> res(n);
  vector<int> res2(n);
  for (int i = 0; i < (n); ++i) {
    if (s[i] == 'S') {
      res[i] = 0;
      res2[i] = 1;
    } else {
      res2[i] = 0;
      res[i] = 1;
    }
  }
  int cnt_S = 0;
  for (int i = 0; i < (n); ++i) {
    if (s[i] == 'T') continue;
    auto itr = upper_bound(res.begin() + i, res.end(), 0);
    if (itr != res.end()) cnt_S++;
  }
  int cnt_T = 0;
  reverse((res2).begin(), (res2).end());
  for (int i = 0; i < (n); ++i) {
    if (s[i] == 'S') continue;
    auto itr = upper_bound(res2.begin() + i, res2.end(), 0);
    if (itr != res2.end()) cnt_T++;
  }
  int ans = n - min(cnt_S, cnt_T) * 2;
  cout << ans << endl;
  return 0;
}
