#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
  cin >> s;
  vector<long long> vi;
  int num = 1, ans = s.size();
  char c = s[0];
  for (long long i = (1); i < (s.size()); i++) {
    if (c != s[i]) {
      c = s[i];
      vi.push_back(num);
      num = 1;
    } else
      num++;
  }
  vi.push_back(num);
  if (s[0] == 'S') {
    int num = min(vi[0], vi[1]);
    ans -= 2 * num;
    vi[0] -= num;
    vi[1] -= num;
    for (int i = 2; i < vi.size(); i += 2) {
      num = min(vi[i], vi[i + 1]);
      ans -= 2 * num;
      vi[i] -= num;
      vi[i + 1] -= num;
      vi[0] += vi[i];
      vi[1] += vi[i + 1];
      num = min(vi[0], vi[1]);
      ans -= 2 * num;
      vi[0] -= num;
      vi[1] -= num;
    }
  } else {
    int num = min(vi[1], vi[2]);
    ans -= 2 * num;
    vi[1] -= num;
    vi[2] -= num;
    for (int i = 3; i < vi.size() - 1; i += 2) {
      num = min(vi[i], vi[i + 1]);
      ans -= 2 * num;
      vi[i] -= num;
      vi[i + 1] -= num;
      vi[1] += vi[i];
      vi[2] += vi[i + 1];
      num = min(vi[1], vi[2]);
      ans -= 2 * num;
      vi[1] -= num;
      vi[2] -= num;
    }
  }
  cout << ans << endl;
}
