program forbidden
  implicit none
  integer :: x,n, ans, d,i,j
  integer,allocatable :: p(:)
  logical :: status

  read(*,*) x, n
  if (n == 0) then
     read(*,*) 
     write(*,*) x
     stop
  end if
  allocate(p(n))
  read(*,*) p
  d = 1000
  do i = 1, maxval(p)+1
     status = .true.
     do j = 1, n
        if ( i == p(j) ) then
           status = .false.
           exit
        end if
     end do
     if (status) then
        if (abs(i-x)<d) then
           ans = i
           d = abs(i-x)
        end if
     end if
  end do
  
  write(*,*) ans
  stop
end program forbidden
