program main
implicit None
	integer(8),allocatable::a(:),b(:),w(:),g(:),g2(:)
	integer(8)::n,k,i,p,j,c
	
	read*,n,k
	allocate(a(n),b(n))
	
	read*,a
	b = a
	
	c = int(log(real(k))/log(real(2)))+1
	allocate(w(c),g(c))
	
	do j = 1,c
		p = 0
		do i = 1,n
			p = p + mod(a(i),2)
			a(i) = a(i)/2
		enddo
		w(j) = p
	enddo
	
	p = 0
	do j = c,1,-1
		if(w(j) >= n-w(j))then
			g(j) = 0
			else
			g(j) = 1
			p = p + 2**(j-1)
			
			if (p > k)then
				g(j) = 0
				p = p-2**(j-1)
			endif
		endif
	enddo
	
	k = 0
	do i = 1,n
		k = k + xor(p,b(i))
	enddo
	
	print "(i0)",k
	
end program main