X = input().rstrip() + "#"
s0 = X[0]
P = []
cnt = 1
for s in X[1:]:
    if s==s0:
        cnt += 1
    else:
        P.append(cnt)
        cnt = 1
    s0 = s
if X[0] == "T":
    P = P[1:]
res = len(X) - 1
for i in range(0,len(P)-1,2):
    if P[i] < P[i+1]:
        res -= P[i]*2
    else:
        res -= P[i+1]*2
print(res)