Ap in array

how to find min no. of elements to replace to make the array ap (arithmetic progression)?