Calculate the number of pages correctly