#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
void ff() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
void in_out_txt() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
int main() {
  ff();
  string str;
  cin >> str;
  int c1 = 0, c2 = 0, z = 0, co = 0;
  for (int i = 0; i < str.size(); i++) {
    if (str[i] == 'S' && z == 0)
      c1++;
    else if (str[i] == 'T')
      c2++, z = 1;
    else if (str[i] == 'S' && z == 1) {
      if (c1 >= c2)
        c2 = 0, c1 -= c2;
      else
        co += c2 - c1, c2 = c1 = 0;
      z = 0;
      i--;
    }
  }
  cout << co * 2 << endl;
  return 0;
}
