s=input()
l=s.find("S")
r=s.rfind("T")
lens=(len(s))
if l==-1 or r==-1:
    print(lens)
else:
    rest=l+lens-r-1
    s=s[l:r+1]
    from collections import Counter
    s=list(Counter(s).values())
    if len(s)==0:
        print(rest)
    else:
        print(rest+abs(s[0]-s[1]))