#include <bits/stdc++.h>
using namespace std;
const int vx[4] = {0, 1, 0, -1};
const int vy[4] = {1, 0, -1, 0};
void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
string s;
int main() {
  cin >> s;
  int ans = 0;
  int i = 0;
  while (s[i] == 'T') {
    ans++;
    i++;
  }
  int j = s.size() - 1;
  while (s[j] == 'S') {
    ans++;
    j--;
  }
  int a = 0, b = 0;
  for (int k = (int)i; k < (int)j + 1; k++) {
    if (s[k] == 'S')
      a++;
    else
      b++;
  }
  cout << ans + abs(a - b) << endl;
}
