How to invest in index funds to build long-term wealth