X = input()
if len(X) >= 150000:
    for i in range(len(X)):
        if X[i] == "S":
            count_T = X[i:].count("T")
            break
    for i in range(len(X)-1,-1,-1):
        if X[i] == "T":
            count_S = X[:i+1].count("S")
            break
    pair = min(count_T,count_S)
    ans = len(X) - 2 * pair
    print(ans)
else:
    for i in range(10**5):
        note = X
        X = X.replace("ST","")
        if note == X:
            break
    print(len(X))