program abc
	implicit none
	integer(8) :: k,n
    integer :: l,m,x,y
	integer :: an(200000)=0 

	read(*,*) k,n
	read(*,*) (an(m),m=1,n)
 
	x = 0

	do m = 1, n
    	if(m /= n) then
	    	l = an(m+1) - an(m)
        else
        	l = k - an(m) + an(1)
        endif
        
		if(l >= x) then
    		x = l
		endif
	enddo
	
	y = k - x
 
	write(*,*) y

end program abc