x=input()
ans=0
ind=x.find("ST")
while(ind!=-1):
    ans+=2
    s_ind=ind-1
    t_ind=ind+2
    while(0<=s_ind and t_ind<len(x) and x[s_ind]=="S" and x[t_ind]=="T"):
        ans+=2
        s_ind-=1
        t_ind+=1
    ind=x.find("ST",ind+1)
print(len(x)-ans)