#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const long long mod = 1e9 + 7;
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
ll dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
ll cb(ll a, ll b);
int main() {
  string x;
  cin >> x;
  ll n = x.size();
  bool flag = true;
  ll l = 0, r = 0, t = 0, s = 0;
  for (ll i = 0; i < n; i++) {
    if (flag && x[i] == 'T') l++;
    if (x[i] == 'S') {
      flag = false;
      s++;
    }
    if (!flag && x[i] == 'T') t++;
  }
  bool flag0 = false;
  flag = true;
  for (int i = n - 1; i > 0; i--) {
    if (x[i] == 'T') flag = false;
    if (!flag && x[i] == 'S') {
      flag0 = true;
      break;
    }
    if (x[i] == 'S') r++;
  }
  if (!flag0) s = 0;
  cout << l + r + abs(s - t);
  return 0;
}
ll cb(ll a, ll b) {
  ll ans = 1;
  for (ll i = 0; i < b; i++) ans *= (a - i);
  for (ll i = 0; i < b; i++) ans /= (b - i);
  return ans;
}
ll gcd(ll a, ll b) {
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
