arr = list(input())
ans = 0
ct= 0
cs= 0
for i in range(len(arr)):
    if arr[i] == "S":
        cs +=1
        
    
    else:
        ct +=1
        
        if cs >= ct:
            ans +=1
           
    
    try:
        if arr[i] == "T" and arr[i+1] == "S":
            cs=0
            ct=0
    
    except:
        pass

print(len(arr)-2*ans)
