program test
integer::n, x, ans, i, t, k, p
allocatable::a(:)
read(*,*)n, x
allocate(a(n))
read(*,*)(a(i), i=1,n)

t=x-a(1)
ans=abs(t)

do i=1,n
t=x-a(i)
k=abs(t)
call subr4(ans,k,p)
ans=p
end do
write(*,*)ans

end program test

subroutine subr4(a,b,q)
  implicit none
  integer :: a, b, q
  integer :: m, n, k
  ! step 1
  m = a
  n = b
  do
     ! step 2
     k = mod(m, n)
     ! step 3
     if (k == 0) then
        q=n
        exit
     end if
     ! step 4
     m = n
     n = k
  end do
 end subroutine subr4