x = input()

forward = 0
back = 0
for index, char in enumerate(x):
    if char == "S":
        forward = index
        break
for index, char in enumerate(x[::-1]):
    if char == "T":
        back = index
        break

res = x[forward:-back]

print(forward +
      back +
      abs(res.count("T") - res.count("S")))
