#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j;
  string str1;
  cin >> str1;
  int l = -1;
  int curr = 0;
  int ans = 0;
  for (i = 0; i < str1.size(); i++)
    if (str1[i] == 'S')
      break;
    else
      ans++;
  for (j = str1.size() - 1; j >= 0; j--)
    if (str1[j] == 'T')
      break;
    else
      ans++;
  l = i;
  for (i = i; i < j + 1; i++) {
    if (str1[i] == 'S')
      curr++;
    else
      curr--;
    if (curr < 0) {
      ans += (i - l);
      l = i;
    }
    if (curr == 0) {
      l = i;
    }
  }
  cout << ans;
  return 0;
}
