program main
   implicit none
   integer(8) n,k,keta
   integer(8) ::i,j,ans=0,eans=0
   integer(8), allocatable,dimension(:)::a,han
   read(*,*)n,k
   allocate(a(n))
   read(*,*)a
   keta=int(log(real(k,8))/log(2.0_8)+0.00000001)+1
   allocate(han(keta))
   han=0
   do i=1,n
      do j=1,keta
         if(btest(a(i),j))then
            han(j)=han(j)+1
         else
            han(j)=han(j)-1
         endif
      enddo
   enddo
   do i=1,keta
      if(han(i)<0)then
         ans=ans+2**i
      endif
   enddo
   if(ans>k)ans=ans-2**keta
   do i=1,n
      eans=eans+xor(ans,a(i))
   enddo
   write(*,*)eans
end program main
