X = list(input())
N = len(X)
NHALF = N // 2

def solve2():
    leadt = 0
    nt, ns = 0, 0
    for i in range(N):
        if nt == NHALF:
            break
        if X[i] == 'T':
            nt += 1
            if ns == 0:
                leadt += 1
        else:
            ns += 1
    return N - 2 * min(ns, NHALF - leadt)


print(solve2())