import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    X=input()
    len_x=len(X)
    for i,x in enumerate(X):
        if x=="S":
            left_s=i
            break
    for i in range(len_x-1,-1,-1):
        if X[i]=="T":
            right_t=i
            break
    XX=X[left_s:right_t+1]
    xxc=Counter(XX)
    print(left_s+len_x-right_t-1+abs(xxc['S']-xxc['T']))

if __name__=='__main__':
    main()