#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
  cin >> s;
  int i = 0;
  while (i < s.size() && s[i] == 'T') i++;
  int res = 0;
  while (i < s.size()) {
    int j = i;
    while (j < s.size() && s[j] == 'S') j++;
    if (j == s.size()) break;
    int x = j - i;
    int k = j;
    while (k < s.size() && s[k] == 'T') k++;
    int y = k - j;
    res += min(x, y) * 2;
    i = k;
  }
  cout << s.size() - res << endl;
}
