program XXOR
  implicit none
  integer :: n, m, i, j
  integer(8) :: k, a(100000) = 0_8, x = 0_8, f = 0_8
  read(*,*) n, k
  read(*,*) a(1:n)
  do i = 40, 0, -1
    m = 0
    do j = 1, n
      if (btest(a(j),i)) m = m+1
    end do
    if (m < n-m) x = ibset(x,i)
    if (x > k) x = ibclr(x,i)
  end do
  do i = 1, n
    f = f+xor(x,a(i))
  end do
  write(*,'(i0)') f
end program XXOR