import sys

input_methods=['clipboard','file','key']
using_method=1
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(IN())
mod=1000000007

#+++++

def main():
	#a = int(input())
	#b , c = tin()
	s = list(input())[:-1]
	while True:
		p=''
		pi=-1
		is_exist_st=False
		#pa(s)
		for i, c in enumerate(s):
			if p == 'S' and c == 'T':
				s[pi] = 'e'
				s[i] = 'e'
				#print(s)
				is_exist_st = True
				p=''
				for bj in range(i):
					if s[i-1-bj]!='e':
						p=s[i-1-bj]
						pi=i-1-bj
						break
				
			elif c == 'e':
				pass
			else:
				p=c
				pi=i
		
		if not is_exist_st:
			break	
	return len(s)-s.count('e')
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)