The proceeds from a foreclosure sale are distributed in the following order:

(1) To pay the costs and expenses of the sale, including trustee and attorney fees;

(2) To pay the debt secured by the mortgage or deed of trust;

(3) To pay debts secured by junior mortgages or deeds of trust, in their order of priority; and

(4) The remainder, if any, goes to the owner of the property or his or her successor in interest.

Civil Code Section 2924k.