Find first duplicate number in an array containing numbers from 1 to n