S = input()

c = 0
for i in range(len(S)):
    if S[i] == "T":
        c +=1
    else:
        break

cc = 0
for i in range(len(S)-1,-1,-1):
    if S[i] == "S":
        cc += 1
    else:
        break

s,t = 0,0
for i in range(c,len(S)-cc):
    if S[i] == "S":
        s += 1
    elif S[i] == "T":
        t += 1

print(c+cc+abs(s-t))