s = input()
try:
    rt = s.rindex("T")
except ValueError:
    rt = -1
try:
    ls = s.index("S")
except ValueError:
    ls = -1
if rt == -1:
    st, sc = 0, 0
elif ls == -1:
    st, sc = 0, 0
else:
    st = s[ls : rt + 1].count("T")
    sc = s[ls : rt + 1].count("S")
ans = len(s) - min(st, sc) * 2

print(ans)
