import sys
input=sys.stdin.readline

def main():
    X = input().strip()
    while 1:
        si = X.find("ST")
        if si == -1:
            break
        sc = 1
        for i in range(si-1,-1,-1):
            if X[i] != "S":
                break
            sc += 1
        tc = 1
        for i in range(si+2,len(X)):
            if X[i] != "T":
                break
            tc += 1
        c = min(sc,tc)
        X = X[:max(0,si-c+1)] + X[min(len(X),si+c+1):]
    print(len(X))

if __name__ == '__main__':
    main()
