#include <bits/stdc++.h>
using ll = long long;
constexpr ll INF = 10000000000;
using namespace std;
int main() {
  string s;
  cin >> s;
  int tc = 0;
  int sc = 0;
  int cnt = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'T') {
      tc++;
    } else {
      break;
    }
  }
  for (int i = s.size() - 1; i >= 0; i--) {
    if (s[i] == 'S') {
      sc++;
    } else {
      break;
    }
  }
  int start = tc;
  int goal = s.size() - sc - 1;
  int T = 0;
  int S = 0;
  for (int i = start + 1; i < goal; i++) {
    if (s[i] == 'S')
      S++;
    else
      T++;
  }
  int ans = tc + sc;
  ans += max(S, T) - min(S, T);
  cout << ans << endl;
}
