If you'd invested $1,000 in these 3 stocks in the 1980s, you'd be a millionaire today

If you had invested $1,000 in each of just three companies back in the 1980s — Apple, Microsoft and M&T Bank — you would be a millionaire today.

That's according to Standard and Poor's Howard Silverblatt, who calculated as follows, using data through the end of 2016:

If you put $1,000 in Apple in 1980, you would have $228,113

If you put $1,000 in Microsoft in 1987, you would have $546,996

And if you put $1,000 in M&T in 1980, you would have $640,948

So, having started with only $3,000, you would have accumulated a grand total of $1,485,853.

Markets are notoriously fickle, though, and winning big in the market is not just a matter of, say, investing in tech stocks at the right time. Sun Microsystems seemed like a safe bet in the 1990s: Its motto was "we're the dot in dot com." It later became infamous as the dot in the dot com bubble, after that bubble burst.

Sun's share price rose to $250 in 2000 before bottoming out at $10 just a couple of years later. The struggling business was acquired by Oracle in 2009.

Stocks are hit or miss. But when you hit, you can hit big, especially if you follow Warren Buffett's advice: You can make a lot of money in the market "by owning good companies for long periods of time."