def main():
    X = str(input())
    N = len(X)
    s = []
    t = []
    s_ = 1
    t_ = 1
    for i in range(N-1):
        if X[i] == "S" and X[i+1] == "S":
            s_ += 1
        elif X[i] == "T" and X[i+1] == "T":
            t_ += 1
        elif X[i] == "S" and X[i+1] == "T":
            s.append(s_)
            s_ = 1
        else:
            t.append(t_)
            t_ = 1

    if X[-1] == "T":
        t.append(t_)
    else:
        s.append(s_)
    ans = 0
    if X[0] == "S":
        M = len(t)
        for i in range(M):
            ans += min(s[i],t[i])
    else:
        M = len(t)-1
        for i in range(M):
            ans += min(s[i],t[i+1])

    print(N-2*ans)

if __name__ == "__main__":
    main()