PROGRAM ATCODER

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

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

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

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

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

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

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

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

write(*,'(i0)') ans

END PROGRAM ATCODER
