Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def slv2(N, K, A):
    ans = (-1, -1)
    for k in range(K+1):
        tmp = 0
        for a in A:
            tmp += k ^ a
        if ans[0] < tmp:
            ans = (tmp, k)
    
    print(ans)
    return ans[0]


@mt
def slv(N, K, A):
    max_k_A = max(max(A), K)
    # print(max_k_A)
    mi = int(math.ceil(math.log2(max_k_A)))
    # print('----', mi, math.log2(max_k_A))

    ans = 0
    ak = 0
    for i in range(mi-1, -1, -1):
        s0 = 0
        s1 = 0
        for a in A:
            if ak + (1 << i) <= K:
                s1 += (a & (1 << i)) ^ (1 << i)
            s0 += (a & (1 << i)) ^ (0)
        ans += max(s0, s1)
        if s1 > s0:
            ak |= (1 << i)
    #     print(i, s0 - s1)
    # print(ak)
    return ans


def main():
    N, K = read_int_n()
    A = read_int_n() 
    print(slv(N, K, A))

    # N = 10
    # K = random.randint(0, 100)
    # A = [random.randint(0, 100) for _ in range(N)] 
    # print(N, K)
    # print(' '.join(map(str, A)))
    # print(slv2(N, K, A))
    # print(slv(N, K, A) == slv2(N, K, A))   


if __name__ == '__main__':
    main()


Fixed submission:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def slv2(N, K, A):
    ans = (-1, -1)
    for k in range(K+1):
        tmp = 0
        for a in A:
            tmp += k ^ a
        if ans[0] < tmp:
            ans = (tmp, k)
    
    print(ans)
    return ans[0]


@mt
def slv(N, K, A):
    max_k_A = max(max(A), K)
    # print(max_k_A)
    mi = int(math.ceil(math.log2(max_k_A)))
    # print('----', mi, math.log2(max_k_A))

    ans = 0
    ak = 0
    for i in range(mi-1, -1, -1):
        s0 = 0
        s1 = 0
        i1 = 1 << i
        for a in A:
            if ak + i1<= K:
                s1 += (a & i1) ^ i1
            s0 += (a & i1) ^ (0)
        ans += max(s0, s1)
        if s1 > s0:
            ak |= i1
    #     print(i, s0 - s1)
    # print(ak)
    return ans


def main():
    N, K = read_int_n()
    A = read_int_n() 
    print(slv(N, K, A))

    # N = 10
    # K = random.randint(0, 100)
    # A = [random.randint(0, 100) for _ in range(N)] 
    # print(N, K)
    # print(' '.join(map(str, A)))
    # print(slv2(N, K, A))
    # print(slv(N, K, A) == slv2(N, K, A))   


if __name__ == '__main__':
    main()