s=str(input())
co=int(1)
n=len(s)
A=[]
for i in range(1,n):
    if s[i]!=s[i-1]:
        A.append(co)
        co=1
    else:
        co+=1
A.append(co)
m=len(A)
how=0
if s[0]=='T':
    how=1

A.append(0)
for i in range(how,m-how):
    if i%2!=how:
        continue

    if A[i]<A[i+1]:
        n-=2*A[i]
    else:
        n-=2*A[i+1] 
print(n)