x=input()
a=[1]
for i in range(1,len(x)):
    if x[i]==x[i-1]:
        a[-1]+=1
    else:a+=[1]
ans=0    
if x[0]=="T":
    ans+=a.pop(0)
if x[-1]=="S":
    ans+=a.pop(-1)
    
while len(a)>1:
    a=[i-j for i,j in zip(a[::2],a[1::2]) if i!=j]
    while a and a[0]<0:
        ans+=abs(a.pop(0))
    while a and a[-1]>0:
        ans+=a.pop(-1)
    b=[]    
    if a:
        b=a[0]
        for i in range(1,len(a)):
            if a[i]*a[i-1]>0:
                b[-1]+=a[i]
            else:b+=a[i]
    a=[abs(i) for i in b]
            
print(ans+abs(a[0]) if a else ans) 