X=raw_input()
while 1:
    if 'SSSSSSSSSSSSSSSTTTTTTTTTTTTTTT' in X:
       X=X.replace('SSSSSSSSSSSSSSSTTTTTTTTTTTTTTT','')
    elif 'SSSSSSSSSSTTTTTTTTTT' in X:
       X=X.replace('SSSSSSSSSSTTTTTTTTTT','')
    elif 'SSSSSSSTTTTTTT' in X:
       X=X.replace('SSSSSSSTTTTTTT','')
    elif 'SSSSSTTTTT' in X:
       X=X.replace('SSSSSTTTTT','')
    elif 'SSSTTT' in X:
       X=X.replace('SSSTTT','')
    elif 'ST' in X:
       X=X.replace('ST','')
    else:
        break
print len(X)