s = input()
n = len(s)
cs, ct = 0, 0
f1, f2 = True, True

for i in range(n):
    if not f1 and not f2:
        break
    if s[i] == "T" and f1:
        ct += 1
    if s[-(i+1)] == "S" and f2:
        cs += 1
    if s[i] == "S":
        f1 = False
    if s[-(i+1)] == "T":
        f2 = False

print(max(cs, ct)*2)