#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a < b) {
    swap(a, b);
  }
  while (b) {
    long long r = a % b;
    a = b;
    b = r;
  }
  return a;
}
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
int isPrim(int a) {
  if (a == 1) {
    return 0;
  }
  for (int i = 2; i <= (a + 1) / 2; i++) {
    if (a % i == 0) {
      return 0;
    }
  }
  return 1;
}
long long mod_pow(long long x, long long n, long long mod) {
  long long ret = 1;
  while (n > 0) {
    if (n % 2 == 1) {
      ret = (ret * x) % mod;
    }
    x = (x * x) % mod;
    n = n / 2;
  }
  return ret;
}
struct XX {
  int u;
  int v;
  int t;
};
class xxIntu {
 public:
  bool operator()(const XX& riLeft, const XX& riRight) const {
    if ((riLeft.u) == (riRight.u)) {
      return riLeft.v < riRight.v;
    }
    return (riLeft.u) < (riRight.u);
  }
};
int main(int argc, const char* argv[]) {
  string s;
  cin >> s;
  for (int i = 0; i < 200000; i++) {
    int pos;
    pos = (int)s.find("SSSSSSSSSSTTTTTTTTTT");
    if (pos != std::string::npos) {
      s.replace(pos, 20, "");
    }
    pos = (int)s.find("SSSSSSSSSTTTTTTTTT");
    if (pos != std::string::npos) {
      s.replace(pos, 18, "");
    }
    pos = (int)s.find("SSSSSSSSTTTTTTTT");
    if (pos != std::string::npos) {
      s.replace(pos, 16, "");
    }
    pos = (int)s.find("SSSSSSSTTTTTTT");
    if (pos != std::string::npos) {
      s.replace(pos, 14, "");
    }
    pos = (int)s.find("SSSSSSTTTTTT");
    if (pos != std::string::npos) {
      s.replace(pos, 12, "");
    }
    pos = (int)s.find("SSSSSTTTTT");
    if (pos != std::string::npos) {
      s.replace(pos, 10, "");
    }
    pos = (int)s.find("SSSSTTTT");
    if (pos != std::string::npos) {
      s.replace(pos, 8, "");
    }
    pos = (int)s.find("SSSTTT");
    if (pos != std::string::npos) {
      s.replace(pos, 6, "");
    }
    pos = (int)s.find("SSTT");
    if (pos != std::string::npos) {
      s.replace(pos, 4, "");
    }
    pos = (int)s.find("ST");
    if (pos != std::string::npos) {
      s.replace(pos, 2, "");
    }
  }
  cout << s.size() << endl;
  return 0;
}
