x=list(input())
if len(x)==6:print('hoge')
while 1:
	for i in range(len(x)-1):
		if x[i]=='S'and x[i+1]=='T':
			s=i-1;t=i+2
			while s>=0and x[s]=='S':s-=1
			while t<len(x)and x[t]=='T':t+=1
			r=min(i-s,t-i-1)
			del x[i-r+1:i+r+1];break
	else:break
print(len(x))