from itertools import groupby

def main():
    X = input()
    count = 0
    gp = []
    for key,value in groupby(X):
        gp.append(list(value))
    for i in range(len(gp)-1):
        if gp[i][0] == "S":
            count += min(len(gp[i]),len(gp[i+1]))*2
    tmp = len(X)-count
    count = 0
    for i in range(450):
        count += X.count("ST")
        X = X.replace("ST","")
    print(min(len(X),tmp))


if __name__ == '__main__':
    main()