S = input()

st = 0
fn = 0

for i in range(len(S)):
	if S[i]=='T':
		st = st + 1
	else:
		break

for i in range(len(S)):
	if S[len(S)-1-i] == 'S':
		fn = fn + 1
	else:
		break

ans = st + fn

a = 0
b = 0

for i in range(st, len(S)-fn):
	if S[i]=='T':
		a = a + 1
	else:
		b = b + 1
        
print(ans + abs(a-b))
