def ranlength(A):
    num = list(A)
    count = 1
    table = []
    for i in range(len(num)):
        try:
            if num[i] == num[i+1]:
               count = count + 1
            else:
                table.append(count)
                count = 1
        except:
            table.append(count)
    return(table)

X=input()
RL=ranlength(X)
if X[0]=='T':
    RL.pop(0)
A=0
for i in range(len(RL)//2):
    A+=min(RL[2*i],RL[2*i+1])
print(len(X)-A*2)