#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio (false);
    cin.tie (0);
    int n, k_size;
    const int maxbits = 40;
    long long k, ans[maxbits][2], a_max = -1, result[2];
    cin >> n >> k;
    vector<long long> a(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
        if (a_max < a[i])
        {
            a_max = a[i];
        }
    }
    if (k < 2)
    {
        long long onebit_res = 0;
        for (int i = 0; i < n; ++i)
        {
            onebit_res += a[i] ^ k;
        }
        cout << onebit_res << endl;
        return 0;
    }
    memset (ans, -1, sizeof(ans));
    long long two_pow_n[maxbits];
    two_pow_n[0] = 1;
    for (int i = 1; i < maxbits; ++i)
    {
        two_pow_n[i] = two_pow_n[i - 1] * 2;
    }

    for (int x = 0; x < 2; ++x)
    {
        bool flag_switch = false;
        for (int i = maxbits - 1; i >= 0; --i)
        {
            long long mask = 1LL << i;
            if (k & mask)
            {
                for (int j = i; j >= 0; --j)
                {
                    int count = 0;
                    mask = 1LL << j;
                    for (int l = 0; l < n; ++l)
                    {
                        if (a[l] & mask)
                        {
                            ++count;
                        }
                    }
                    ans[j][x] = two_pow_n[j] * (x == 0 ? count : n - count);
                }
                result[x] = ans[i][x];
                k_size = i;
                break;
            }
            else if (a_max & mask || flag_switch)
            {
                flag_switch = true;
                int count = 0;
                for (int l = 0; l < n; ++l)
                {
                    if (a[l] & mask)
                    {
                        ++count;
                    }
                }
                ans[i][x] = two_pow_n[i] * count;
            }
        }
    }

    for (int j = maxbits - 1; j >= 0; --j)
    {
        if (ans[j][0] == -1 || j == k_size)
        {
            continue;
        }
        else
        {
            result[0] += max (ans[j][0], ans[j][1]);
        }
    }
    bool fdp = false;
    for (int j = maxbits - 1; j >= 0; --j)
    {
        if (ans[j][1] == -1 || j == k_size)
        {
            continue;
        }
        else
        {
            long long mask = 1LL << j;
            if (fdp)
            {
                result[1] += max (ans[j][0], ans[j][1]);
            }
            else if (k & mask)
            {
                long long temp[2] = {ans[j][0], ans[j][1]};
                for (int x = j - 1; x >= 0; --x)
                {
                    temp[0] += max (ans[x][0], ans[x][1]);
                }
                for (int x = j - 1; x >= 0; --x)
                {
                    mask = 1LL << x;
                    temp[1] += (k & mask ? max (ans[x][0], ans[x][1]) : ans[x][0]);
                }
                if (temp[0] >= temp[1])
                {
                    result[1] += ans[j][0];
                    fdp = true;
                }
                else
                {
                    result[1] += ans[j][1];
                }
            }
            else
            {
                result[1] += ans[j][0];
            }
        }
    }

    cout << max (result[0], result[1]) << endl;
}

Measured memory_bytes: 1024