def main():
    x = input().replace("ST", "S T").split()
    ans = 0
    tmp = 0
    for i in range(len(x)-1):
        s = x[i].count("S")
        t = x[i+1].count("T")
        ans += max(t-s, 0) + len(x[i]) - s - tmp
        tmp = t- max(t-s, 0)
        if i == len(x)-2:
            ans += len(x[i+1]) - t
    print(ans)

if __name__ == "__main__":
    main()