def main():
    x = input().replace("TS", "T S").split()
    ans = 0
    s = 0
    for i in x:
        s += i.count("S")
        t = i.count("T")
        if t <= s:
            s -= t
            ans += s
        else:
            ans += 2*(t-s)
            s = 0
    print(ans)

if __name__ == "__main__":
    main()