s = list(input())
cnt = 0
while True:
    if s[0] == 'T':
        s.pop(0)
        cnt += 1
    else:
        break
    
while True:
    if s[-1] == 'S':
        s.pop(-1)
        cnt += 1
    else:
        break

cs = 0
ct = 0
for i in range(len(s)):
    if s[i] == 'S':
        cs += 1
    else:
        ct += 1
print(cnt + abs(cs-ct))