stL = list(input())

allC=0
index=0
count=0
while index < len(stL):
    if stL[index]=="S":
        count+=1
    else:
        allC+=count
        count=0
    index+=1

allC2=0
index2=0
count2=0
stL.reverse()
while index2 < len(stL):
    if stL[index2] == "T":
        count2 += 1
    else:
        allC2 += count2
        count2 = 0
    index2 += 1

print(len(stL)-2*min(allC, allC2))