When done right and given enough time, investing in the stock market can make an individual wealthy. But what should investors do to maximize their chances of building such wealth? The short answer: Invest in companies having, or building, a competitive advantage.

If you are investing in pharma stocks, buying companies with successful product portfolios and extensive drug pipelines are crucial. That's because a strong product portfolio can generate the cash flow to fund research and development, along with acquisitions to bolster the product pipeline. In turn, this leads to steadily growing revenue and profits over time, as revenue dries up on existing drugs.

Here are two companies with top-notch products and the pipelines necessary to support future growth. Better yet, both appear to be cheaply valued.

A pharmacist assists a customer.

Image source: Getty Images.

1. Merck

Merck (MRK -0.11%) is best known for the top-selling cancer drug in the world, Keytruda, which has produced a staggering $10.1 billion in sales through the first half of this year.

Most companies would be happy with a single drug in their portfolio, even close to this level of sales. But with a $222 billion market capitalization, Merck, the fifth-largest pharma company in the world, is more than just a one-trick pony. Keytruda comprised only 33% of the drugmaker's $30.5 billion in total first-half sales.

The company's COVID-19 antiviral treatment Lagevrio contributed another $4.4 billion in sales for the first half of 2022. And its human papillomavirus vaccine, Gardasil, chipped in $3.1 billion in sales during the first half of the year. Nearly two dozen of the company's other products made up the remaining portion of Merck's total first-half sales.

The company's tremendous innovation propelled its total sales through the first half of 2022 higher by 38.4% year over year. And the company's growth should continue for the foreseeable future. Merck has a pipeline of more than 100 projects under clinical development, which should give it enough firepower to grow revenue and profits with new product launches. That's why analysts believe the company will deliver 10.5% annual earnings growth over the next five years.

The company also offers income investors a 3.1% dividend yield. This is nearly double the S&P 500 index's 1.6% yield. Merck's dividend payout ratio is set to be just 37.4% in 2022, which makes the market-topping payout relatively safe. 

Best of all, Merck's robust fundamentals also appear to be underappreciated by the financial markets. The stock's forward price-to-earnings (P/E) ratio of 12.1 is just below the pharmaceutical industry's average forward P/E ratio of 13.6. This makes the stock a great all-around buy for investors

2. Sanofi

Sanofi's (SNY -1.56%) $123 billion market cap positions it as the fourth-largest internationally-headquartered pharmaceutical company, and the 11th-largest pharma company on the planet.

Like Merck, Sanofi has a sizable market cap that stems from an impressive product portfolio and pipeline. The company has seven drugs on track to post blockbuster sales in 2022, led by Dupixent, the immunology drug co-owned with Regeneron. And its polio/pertussis vaccine franchise has already topped the blockbuster mark for the year. For those unfamiliar, a blockbuster drug is one that generates annual sales of $1 billion or more.

Along with a pipeline of 87 projects in clinical development, this explains why analysts are predicting 10.3% annual earnings growth for the next five years. 

Aside from Sanofi's encouraging growth potential, the company can provide income investors with a generous 3.6% dividend yield. And based on the projected forward dividend payout ratio of 41.3%, this is a safe yield for investors. 

Sanofi tops off its pairing of high growth and high yield with a value component as well: The stock's forward P/E ratio is just 11.7. For a company of its quality, this is a dirt cheap valuation