#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
const int INF=1001001001;

int main() {
  string s;
  cin>>s;
  int n=s.size();
  stack<char>k;
  for(int i=0;i<n;i++){
    if(k.empty()){k.push(s[i]);}
    else if(s[i]=='S'){k.push(s[i]);}
    else if(s[i]=='T'){
      if(k.top()=='T'){k.push('T');}
      else if(k.top()=='S'){k.pop();}
    }
    //cout<<k.top()<<endl;
  }
  cout<<k.size()<<endl;
  return 0;
}
//#include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
/*#define fast ios_base::sync_with_stdio(0); cin.tie(0)*/
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
const double pi = acos(-1);
typedef long long ll;
int main()
{
	//fast;
	
	ll n,ans;
	cin>>n;
	cout<<n/3;
}