program C
read*,ix,in

if (in==0)then
print*,ix
goto 30
end if
call sub(ix,in)
30 end program

subroutine sub(ix,in)
integer::na(1:in)
read*,(na(j),j=1,in)
ii=0
ij=0
do ixd=0,1000
ii=0
ij=0
 do k=1,in
  if ((ix-ixd)==(na(k)))then
  ii=1
  end if
    if ((ix+ixd)==(na(k)))then
  ij=1
  end if
  end do
  if (ii==0)then
   print*,ix-ixd
   goto 40
   end if
    if (ij==0)then
   print*,ix+ixd
   goto 40
   end if
 end do
40 end subroutine