s=list(input())
n=len(s)
h=[1]*n
i=0
gap=1
cnt=0
r=0
while (i+gap<n) and cnt<500000:
    cnt+=1
    #print(i,i+gap)
    if s[i]=='S' and s[i+gap]=='T':
        h[i]=0
        h[i+gap]=0
        if i>0 and i+gap+1<n:
            i-=1
            gap+=2
            r=i+gap
        else:
            i=r
            gap=1
            r=i+gap
    else:
        i=r
        gap=1
        r=i+gap

print(sum(h))