Calculate total number of pages.