Calculates the maximum page number