def examA():
    bit = 41
    N, K = LI()
    A = LI()
    B = [0]*bit
    for a in A:
        for j in range(bit):
            if a&(1<<j)>0:
                B[j] += 1
    ans = 0
    cnt = 0
    for i in range(bit)[::-1]:
        if N-B[i]<=B[i]:
            ans += (1 << i) * B[i]
        else:
            if cnt+(1<<i)>K:
                ans += (1 << i) * B[i]
            else:
                cnt += (1 << i)
                ans += (1 << i) * (N-B[i])
    print(ans)
    return
# ↑嘘
def examA2():
    bit = 41
    N, K = LI()
    A = LI()
    B = [0]*bit
    ans = 0
    for a in A:
        for j in range(bit):
            if a&(1<<j)>0:
                B[j] += 1
        ans += K^a
    for i in range(bit):
        if (1<<i)&K==0:
            continue
        cnt = 0
        cnt += (1<<i) * B[i]
        for j in range(i+1,bit):
            f = (1<<j)&K
            if f==0:
                cnt += (1 << j) * B[j]
            else:
                cnt += (1 << j) * (N-B[j])
        for j in range(i):
            cnt += max(N-B[j],B[j])*(1<<j)
        ans = max(ans,cnt)
    print(ans)
    return

def examB():
    N, K = LI()
    WP = [LI()for _ in range(N)]
    l = 0; r = 101
    for _ in range(100):
        now = (l+r)/2
        W = [0]*N
        for i,(w,p) in enumerate(WP):
            W[i] = w*(p-now)
        W.sort(reverse=True)
        if sum(W[:K])>=0:
            l = now
        else:
            r = now
    ans = l
    print(ans)
    return

def examC():
    class UnionFind():
        def __init__(self, n):
            self.parent = [-1 for _ in range(n)]
            # 正==子: 根の頂点番号 / 負==根: 連結頂点数

        def find(self, x):
            # 要素xが属するグループの根を返す
            if self.parent[x] < 0:
                return x
            else:
                self.parent[x] = self.find(self.parent[x])
                return self.parent[x]

        def unite(self, x, y):
            # 要素xが属するグループと要素yが属するグループとを併合する
            x, y = self.find(x), self.find(y)
            if x == y:
                return False
            else:
                if self.size(x) < self.size(y):
                    x, y = y, x
                self.parent[x] += self.parent[y]
                self.parent[y] = x

        def same(self, x, y):
            # 要素x, yが同じグループに属するかどうかを返す
            return self.find(x) == self.find(y)

        def size(self, x):
            # 要素xが属するグループのサイズ（要素数）を返す
            x = self.find(x)
            return -self.parent[x]

        def is_root(self, x):
            # 要素の根をリストで返す
            return self.parent[x] < 0

        def roots(self):
            # すべての根の要素をリストで返す
            return [i for i, x in enumerate(self.parent) if x < 0]

        def members(self, x):
            # 要素xが属するグループに属する要素をリストで返す
            root = self.find(x)
            return [i for i in range(self.n) if self.find(i) == root]

        def group_count(self):
            # グループの数を返す
            return len(self.roots())

        def all_group_members(self):
            # {ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
            return {r: self.members(r) for r in self.roots()}
    N, M = LI()
    Uf = UnionFind(N)
    for _ in range(M):
        a, b = LI()
        a -= 1; b -= 1
        Uf.unite(a,b)
    size = [Uf.size(0),Uf.size(1)]
    size.sort()
    rest = N-sum(size)
    size[1] += rest
    ans = size[0]*(size[0]-1)//2 + size[1]*(size[1]-1)//2 - M
    print(ans)
    return

def examD():
    # 一点更新、区間取得
    class segment_():
        def __init__(self, A, n, segfunc, ide_ele=0):
            #####単位元######要設定0or1orinf
            self.ide_ele = ide_ele
            ####################
            self.num = 1 << (n - 1).bit_length()
            self.seg = [self.ide_ele] * 2 * self.num
            self.segfunc = segfunc
            # set_val
            for i in range(n):
                self.seg[i + self.num] = A[i]
                # built
            for i in range(self.num - 1, 0, -1):
                self.seg[i] = self.segfunc(self.seg[2 * i], self.seg[2 * i + 1])

        def update(self, k, r):
            k += self.num
            self.seg[k] = r
            while k:
                k >>= 1
                self.seg[k] = self.segfunc(self.seg[k * 2], self.seg[k * 2 + 1])

        # 値xに1加算
        def add(self, k, x=1):
            k += self.num
            self.seg[k] += x
            while k:
                k >>= 1
                self.seg[k] = self.segfunc(self.seg[k * 2], self.seg[k * 2 + 1])

        def query(self, p, q):
            # qは含まない
            if q < p:
                return self.ide_ele
            p += self.num;
            q += self.num
            res = self.ide_ele
            while p < q:
                if p & 1 == 1:
                    res = self.segfunc(res, self.seg[p])
                    p += 1
                if q & 1 == 1:
                    q -= 1
                    res = self.segfunc(res, self.seg[q])
                p >>= 1;
                q >>= 1
            return res

    N, Q = LI()
    X = LI()
    X.append(inf)
    X.insert(0,-inf)
    Seg = segment_(X, (N+1), lambda a, b: a + b)
    ans = [0]*Q
    for q in range(Q):
        C, D = LI()
        l1 = bisect.bisect_left(X,C-D)
        r1 = bisect.bisect_left(X,C)
        cntl = r1-l1
        cnt1 = C*cntl-Seg.query(l1,r1)
        l2 = bisect.bisect_left(X,C)
        r2 = bisect.bisect_left(X,C+D)
        cntr = r2-l2
        cnt2 = Seg.query(l2,r2)-C*cntr
        #print(cnt1,cnt2)
        ans[q] = cnt1+cnt2+D*(N-cntl-cntr)
    for v in ans:
        print(v)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examA2()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 65392