PROGRAM ATCODER

implicit none
integer(8) :: n, k, sizea, sizek, i, j, sizemax
integer(8),allocatable :: a(:), count(:), size(:), ans(:), x(:)

read(*,*) n, k
allocate(a(n))
allocate(size(n))

read(*,*) (a(i), i=1,n)

sizek = int(log(real(k))/log(real(2)))+1

do i = 1, n
	if (a(i) == 0) then
    	size(i) = 1
    else
		size(i) = log(real(a(i)))/log(2.d0) + 1
	end if
end do

sizea = maxval(size)
sizemax = max(sizea,sizek)

allocate(x(sizek+1))
allocate(ans(sizek+1))
ans = 0
x = 0
allocate(count(sizemax)) ! count(1)=1ビット目が1の数はいくつあるか
count = 0

do i = 1, sizemax
	do j = 1, n
    	if(btest(a(j),i-1))then
        	count(i) = count(i) + 1
        end if
    end do
end do

do i =1, sizek
	do j = 1, i
    	if(count(j) <= n-count(j))then
			x(i) = x(i) + 2**(j-1)
    	end if
    end do
    if (x(i) > k)then
    	x(i) = 0
    end if
end do

do i = 1, sizek
	do j = 1, n
		ans(i) = ans(i) + xor(x(i),a(j))
    end do
end do

x(sizek+1) = k
do j = 1, n
		ans(sizek+1) = ans(sizek+1) + xor(x(sizek+1),a(j))
end do 

write(*,'(i0)') maxval(ans)

END PROGRAM ATCODER
