The primary-mortgage lender has the first lien or right to the property should the borrower default.
The lender would foreclose on the property, then sell it to recoup its investment.
First mortgages are different from second mortgages, which are secondary loans taken out against the available equity.
All mortgages are liens, or legally binding contracts that allow the lender to stake a claim to the property should the borrower stop making payments or otherwise not follow the terms of the contract.
As the first lien, the primary mortgage lender would be first in line to be paid from the proceeds of a foreclosure auction.
Lenders of home equity loans or lines of credit are secondary to the primary mortgage lender.