Baby boomers are set to retire, all 74 million of them, and a good chunk of them will be relocating to towns across the U.S.

A new ranking takes a look at not only which towns may be the most attractive to retirees, but also the most expensive for buying or renting a home.

Realtor.com examined the 500 largest metropolitan areas, focusing on where at least a quarter of the population is aged 60 and up, to get an idea of which cities will face the largest influx of retirees in their community.

They also looked at a range of factors, especially cost of living, to determine which retirement towns are the most expensive.

Realtor.com ranked each of the metros by the total cost to pay down a 15-year mortgage on a median-priced home within them. Buyers were assumed to have a 20 percent down payment and a 5 percent mortgage interest rate.

The ranking also focused on towns where at least a quarter of the population is aged 60 and up and where the most folks in this age group moved to between 2011 and 2015. "We included only markets that had a high share of realtor.com listings with mentions of 'retirement,' 'aging in place,' 'ground-floor master bedrooms' and similar phrases," the report said.

These towns, in ascending order, were at the top of the list in terms of high housing costs:

10. Ocean City, N.J.

This New Jersey coastal city offers classic Jersey Shore beaches, amusement parks and a boardwalk. Real estate prices currently are $413 per square foot and the median home price is $629,900.