Classification of compact ancient solutions to the Ricci flow on surfaces