program main
  implicit none
  integer(8) :: n, i, d, e, k, res, x, b(0:42)
  integer(8), allocatable :: a(:)
  read (*, *) n, k
  allocate (a(n))
  read (*, *) a

  b(:) = 0
  do i = 1, n
    do d = 0, 42
      if (btest(a(i), d)) b(d) = b(d) + 1
    end do
  end do

  res = f(k, b, n)
  do d = 0, 42
    x = k
    if (.not. btest(x, d)) cycle
    x = ibclr(x, d)
    do e = 0, d - 1
      if (b(e) * 2 >= n) then
        x = ibclr(x, e)
      else
        x = ibset(x, e)
      end if
    end do
    res = max(res, f(x, b, n))
  end do
  print "(i0)", res
  contains

  integer(8) function f(x, b, n)
    integer(8), intent(in) :: x, b(0:42), n
    integer(8) :: d
    f = 0
    do d = 0, 42
      if (btest(x, d)) then
        f = f + (n - b(d)) * 2 ** d
      else
        f = f + b(d) * 2 ** d
      end if
    end do
  end function
end program main
