An Algorithm for Document Reconstruction