#include<bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

#define REP(i, n) for (int i = 0; i < (n); ++i)

#define int long long

#define vec(a,n) vector<int> (a)((n))

#define Vec(a,n) vector<string> (a)((n))

using namespace std;

signed main(){
	string a;
	int s,ans=0;
	cin>>a;
	REP(i,n){
		if(a[i] == 'S') s++;
		if(s!=0 && a[i] =='T'){
			ans++;
			s--;
		}
	}
	cout<<ans;
	return 0;
	
	
}
