import collections

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

if __name__ == "__main__":
    main()