PROGRAM ATCODER

implicit none
integer(8) :: n, k, i, j, sizemax_a, sizemax_k, x_ans
integer(8),allocatable :: a(:), count(:), x(:), ans(:)

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

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

if(k==0)then
	write(*,'(i0)') sum(a)
    stop
end if

sizemax_k = log(real(k))/log(2.d0) + 1
allocate(x(sizemax_k)) ! x(1)に2^0、x(2)に2^1、、、
allocate(ans(sizemax_k))
allocate(count(sizemax_k)) 

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

ans(1) = 0
if (mod(k,2) /= 0)then
	do i = 1, n
		ans(1) = ans(1) + xor(k-1,a(i))
    end do
end if


do i = 2, sizemax_k
	x(i) = 0
    do j= 1, i-1
    	if (count(j) > n-count(j)) then
        	x(j) = 0
		else
        	x(j) = 1
        end if
	end do
    ans(i) = 0
    x_ans = k
    do j = 1, i
    	if (btest(k,j-1) .and. x(j) == 0) then
    		x_ans = x_ans - 2**(j-1)
		end if   
        if (btest(k,j-1)) then
        else if(x(j) == 1) then
        	x_ans = x_ans + 2**(j-1)
        end if
    end do
    do j = 1, n
    	ans(i) = ans(i) + xor(x_ans,a(j))
	end do 
end do

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

END PROGRAM ATCODER

