In any foreclosure of a mortgage upon real estate by action, the holder of the mortgage may purchase the mortgaged premises, or any part thereof, at such foreclosure sale, if the holder of the mortgage bids fairly and in good faith, and bids the fair and reasonable value thereof, less the sum of the balances due, as of the date of sale, on any prior liens or encumbrances upon the mortgaged premises, including liens or charges for real property taxes and special assessments. In no event may the holder of the mortgage be required to bid a sum in excess of the debt adjudged by the court to be due, with costs and disbursements taxed in the action in which the sale is made, and costs and expenses of the sale.
SDCL 21-47-15