program sample
	implicit none
    integer(8) :: X,N,i,j,count
    integer(8),allocatable :: a(:),b(:)
    
    read(*,*) X,N
    
    allocate(a(N))
    
    allocate(b(N))
    
    count = X
    
    if (N==0) then
    	write(*,*) X
    else
    	read(*,*) a
    	do i=0,N
        	do j=1,N
            !write(*,*) i
            !write(*,*) count+i*(-1)**i
            	if (a(j) == count+i*(-1)**i) then
                	b(j) = 0
            	else
                	b(j) = count+i*(-1)**i
                end if
                
            end do
            count = count+i*(-1)**i
            if (minval(b) == maxval(b)) then
            	exit
            end if
        end do
        write(*,*) minval(b)
    end if
    
    
    deallocate(a)
    deallocate(b)
    stop
end program sample