#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  cin >> str;
  long Length = str.size();
  long length = Length;
  long j = 0;
  for (j = 0; j < length; j++) {
    long count = 0;
    long minus = 0;
    long flag = 0;
    for (long i = j; i < length; i++) {
      if (str[i] == 'S') {
        if (flag == 0) {
          count = i;
        }
        flag++;
      }
      if (flag != 0 && str[i] == 'T') {
        flag--;
        if (flag == 0) {
          minus += (i - count + 1);
        }
      }
    }
    if (length > Length - minus) {
      length = Length - minus;
    }
  }
  cout << length << endl;
  return 0;
}
