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