X = input().strip()
flag = 0
cntS = 0
cntT = 0
num = 0
for i in range(len(X)):
    if flag==0 and X[i]=="S":
        num += min(cntS,cntT)
        cntS = 0
        cntT = 0
        flag = 1
        cntS += 1
    elif flag==1 and X[i]=="S":
        cntS += 1
    elif flag==1 and X[i]=="T":
        cntT += 1
        flag = 0
    elif flag==0 and X[i]=="T":
        cntT += 1
num += min(cntS,cntT)
print(len(X)-2*num)      