S = input()
lS = len(S)
tmp = ["S","T"]
f = 0
cnt = 0
l = []
for i in range(lS):
    if (S[i] == tmp[f]):
        cnt += 1
    else:
        l.append(cnt)
        cnt = 1
        f ^= 1
if (cnt != 0):l.append(cnt)
if (len(l) % 2 != 0) : l.append(0)
ll = len(l)
for i in range(0,ll,2):
    m = min(l[i],l[i+1])
    l[i] -= m
    l[i+1] -= m

print(sum(l))