X = input()
n = len(X)

leftt = 0
while X[leftt] == 'T':
    leftt += 1

rights = 0
while X[n - rights -1] == 'S':
    rights += 1

ss, ts = 0, 0
for i in range(leftt, n-rights):
    if X[i] == 'S':
        ss += 1
    else:
        ts += 1

ans = leftt + rights + abs(ss-ts)
print(ans)
