(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

(defmacro nlet (name args &body body)
  (labels ((ensure-list (x) (if (listp x) x (list x))))
    (let ((args (mapcar #'ensure-list args)))
      `(labels ((,name ,(mapcar #'car args) ,@body))
         (,name ,@(mapcar #'cadr args))))))

(declaim (inline split-ints-into-vector))
(defun split-ints-into-vector (string dest-vector &key (offset 0) (key #'identity))
  (declare (string string)
           (function key)
           ((array * (*)) dest-vector)
           ((integer 0 #.most-positive-fixnum) offset))
  (loop with position = 0
        for idx from offset below (length dest-vector)
        do (setf (values (aref dest-vector idx) position)
                 (parse-integer string :start position :junk-allowed t))
           (setf (aref dest-vector idx) (funcall key (aref dest-vector idx)))
        finally (return dest-vector)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Hauptteil
(defun main ()
  (declare #.OPT)
  (let* ((n (read))
         (k (read))
         (as (make-array n :element-type 'uint62))
         (max-digit 40) ; 39-th ... 0-th
         (zeros (make-array max-digit :element-type 'uint32)))
    (declare ((integer 0 #.(expt 10 5)) n)
             ((integer 0 #.(expt 10 12)) k))
    (split-ints-into-vector (read-line) as)
    (dotimes (pos max-digit)
      (setf (aref zeros pos)
            (loop for i below n
                  count (= 0 (ldb (byte 1 pos) (aref as i))))))
    (println
     (nlet recurse ((pos (- max-digit 1)) (limited t))
       (declare (values uint62))
       (if (= -1 pos)
           0
           (let ((c (aref zeros pos)))
             (declare ((integer 0 #.(expt 10 5)) c))
             (if limited
                 (if (zerop (ldb (byte 1 pos) k))
                     (+ (* (- n c) (ash 1 pos))
                        (recurse (- pos 1) t))
                     (max (+ (* (- n c) (ash 1 pos))
                             (recurse (- pos 1) nil))
                          (+ (* c (ash 1 pos))
                             (recurse (- pos 1) t))))
                 (if (> c (- n c))
                     ;; choose 1
                     (+ (* c (ash 1 pos))
                        (recurse (- pos 1) nil))
                     (+ (* (- n c) (ash 1 pos))
                        (recurse (- pos 1) nil))))))))))

;; Observation: Memoization makes little difference.

;; On the one hand it takes O(NlogK) to make ZEROS. On the other hand, the
;; complexity of (nlet ...)  form is O((logK)^2) because in the branch, (max A
;; B), A takes only O(logK) time. By memoization it is reduced to O(logK). To
;; sum up, naive recursion takes O(NlogK + (logK)^2) while memoized recursion
;; does O(NlogK): i.e. it doesn't matter unless K is extraordinary large (e.g. K
;; = Ω(2^N)).

#-swank(main)


Measured memory_bytes: 33252