X = raw_input()

count = 0
count2 = 0
n = len(X)

if X[n-1] == 'S':
    for i in range(n):
    
        if X[n-1-i] == 'S':
        
            count +=1
        else:
            break
else:
    for i in range(n):
        if X[n-1-i] == 'T':
            count2 +=1
        else:
            break
    for i in range(n-count2):
        if X[n-1-i-count2] == 'S':
            count +=1
        else:
            break
print max((count-count2)*2,0)
