x=input()
length=len(x)
x=x+"E"
ch=x[0]
lists=[]
counter=1
for i in range(length):
    if x[i]==x[i+1]:
        counter+=1
    elif x[i]!=x[i+1] :
        lists.append(counter)
        counter=1
uselist=[]
if x[0]=="S" and x[-2]=="S":
    lists.append(0)
    for i in range(0,len(lists),2):
        uselist.append((lists[i],lists[i+1]))

elif x[0]=="S" and x[-2]=="T":
    for i in range(0,len(lists),2):
        uselist.append((lists[i],lists[i+1]))
   
elif x[0]=="T" and x[-2]=="S":
    lists.insert(0,0)
    lists.append(0)
    for i in range(0,len(lists),2):
        uselist.append((lists[i],lists[i+1]))

elif x[0]=="T" and x[-2]=="T":
    lists.insert(0,0)
    for i in range(0,len(lists),2):
        uselist.append((lists[i],lists[i+1]))
 
        
num=len(uselist)
uselist.append((0,0))
minus=0
a=0
b=0
i=0
while i<=num-1:
    if uselist[i][0]<=uselist[i][1]:
        minus+=uselist[i][1]-uselist[i][0]
        i+=1
    elif uselist[i][0]>uselist[i][1]:
        a=uselist[i][0]
        b=uselist[i][1]
        while a<=b and i+1<=num:
            a+=uselist[i+1][0]
            b+=uselist[i+1][1]
            i+=1
        if a<=b:
            minus+=b-a
        else:
            minus+=a-b
        a=0
        b=0
        i+=1
print(minus)
            