program forbidden

 implicit none
 integer::x,n,i,j,d,ans,cou,k
 integer,allocatable::p(:),b(:),c(:),e(:)
 integer::a(100)

 read*,x,n
 !print*,x,n
 allocate(p(n))
 read*,p
 !print*,p

 j=1
 cou=0
 a=0

 do i=1,100
    do k=1,n
     !print*,p(k)
     if(i/=p(k)) then
     cou=cou+1
     end if
    end do
   !print*,answer
  if(cou==n) then
   a(j)=i
   !print*,a(j)
   j=j+1
  end if
  
 end do 
 
 allocate(b(j),c(j),e(j))
 b=0
 c=0
 e=100
 b=a(1:j)
 !print*,b

 c=abs(x-b)
 d=minval(c)
 
 do i=1,j
  if(abs(x-b(i))==d) then

   e(i)=b(i)
  end if
 end do
 
 ans=minval(e)
 print*,ans

end program forbidden

