#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int cnt_t = 0;
  int cnt_s = 0;
  int left = 0;
  int right = 0;
  int n = s.size();
  for (int i = 0; i < n; i++) {
    if (s.at(i) == 'S') break;
    left++;
  }
  for (int i = 0; i < n; i++) {
    if (s.at(n - 1 - i) == 'T') break;
    right++;
  }
  for (int i = left; i < n - right; i++) {
    if (s.at(i) == 'S')
      cnt_s++;
    else
      cnt_t++;
  }
  cout << left + right + (max(cnt_s, cnt_t) - min(cnt_s, cnt_t)) << endl;
}
