Classification of ancient compact solutions to the Ricci flow on surfaces