program xxor
  implicit none
  integer(8)              :: n, k, d, s, m
  integer(8)              :: i, j, p
  integer(8), allocatable :: a(:)
  read(*,*) n, k
  allocate(a(n))
  read(*,*) a(:)
  d = int(log(real(k,8))/log(2.d0)) + 1
  p = 2**d
  m = 0
  do i = d, 0, -1
     s = 0_8
     do j = 1, n
        if (and(p,a(j)) .eq. p) s = s + 1
     end do
     if (s .lt. n-s .and. m+p .le. k) then
        m = m + p
     end if
     p = p / 2
  end do
  p = 0
  do i = 1, n
     p = p + xor(m,a(i))
  end do
  deallocate(a)
  write(*,'(i0)') p
  stop
end program xxor