#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> Pi; typedef map<int,int> MPi; typedef pair<Int,Int> Pl;
const int mod = 1000000007;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) v.begin(),v.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
	cin.tie(nullptr); ios::sync_with_stdio(false);

	string s; cin>>s; int ans=0,key=0;
	for (int i = 0; i < s.size(); i++){
		if(s[i]=='S')key++;
		else{
			if(key){
				int a=0;
				for (int j = 0; j < key; j++){
					if(s[i+j]=='T')a++;
					else break;
				}
				ans+=a;
			}
			key=0;
		}
	}
	cout<<max(0u,s.size()-ans*2)<<'\n';
}