///////////////////////////////////////////////////////////////////////////////

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <typeinfo>
#include <numeric>

using namespace std;

///////////////////////////////////////////////////////////////////////////////

#define pb push_back
#define V vector
#define ll long long
#define ull unsigned long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)

struct UnionFind
{
        unsigned ll *parent, *count, *rank;

        UnionFind(unsigned ll n) {
                parent = new unsigned ll[n+1];
                count = new unsigned ll[n+1];
                rank = new unsigned ll[n+1];
                for (unsigned ll i = 0UL; i < n+1; ++i) {
                        parent[i] = i;
                        count[i] = 1;
                        rank[i] = 0;
                }
        }

        unsigned ll root(unsigned ll i) {
                if (parent[i] == i) return i;
                parent[i] = root(parent[i]);
                return parent[i];
        }

        void unite(unsigned ll i, unsigned ll j) {
                unsigned ll rooti = root(i);
                unsigned ll rootj = root(j);

                if (rooti == rootj) return;

                if (rank[rootj] < rank[rooti]) {
                        parent[i] = parent[j] = parent[rootj] = rooti;
                        count[rooti] += count[rootj];
                }
                else {
                        parent[i] = parent[j] = parent[rooti] = rootj;
                        count[rootj] += count[rooti];
                        if (rank[rootj] == rank[rooti]) rank[rootj]++;
                }
        }

        bool same(unsigned ll i, unsigned ll j) {
                return root(i) == root(j);
        }
};

struct T2 {
        ll t0;
        ll t1;
};

struct T3 {
        ll t0;
        ll t1;
        ll t2;
};

struct T4 {
        ll t0;
        ll t1;
        ll t2;
        ll t3;
};

bool operator<(const T2 &lhs, const T2 &rhs)
{
        if (lhs.t0 != rhs.t0) return lhs.t0 < rhs.t0;
        return lhs.t1 < rhs.t1;
}

bool operator>(const T2 &lhs, const T2 &rhs)
{
        if (lhs.t0 != rhs.t0) return lhs.t0 > rhs.t0;
        return lhs.t1 > rhs.t1;
}

bool operator==(const T2 &lhs, const T2 &rhs)
{
        if (lhs.t0 != rhs.t0) return false;
        return lhs.t1 == rhs.t1;
}

bool operator!=(const T2 &lhs, const T2 &rhs)
{
        return !(lhs == rhs);
}

bool operator<(const T3 &lhs, const T3 &rhs)
{
        if (lhs.t0 != rhs.t0) return lhs.t0 < rhs.t0;
        if (lhs.t1 != rhs.t1) return lhs.t1 < rhs.t1;
        return lhs.t2 < rhs.t2;
}

bool operator>(const T3 &lhs, const T3 &rhs)
{
        if (lhs.t0 != rhs.t0) return lhs.t0 > rhs.t0;
        if (lhs.t1 != rhs.t1) return lhs.t1 > rhs.t1;
        return lhs.t2 > rhs.t2;
}

bool operator==(const T3 &lhs, const T3 &rhs)
{
        if (lhs.t0 != rhs.t0) return false;
        if (lhs.t1 != rhs.t1) return false;
        return lhs.t2 == rhs.t2;
}

bool operator!=(const T3 &lhs, const T3 &rhs)
{
        return !(lhs == rhs);
}

bool operator<(const T4 &lhs, const T4 &rhs)
{
        if (lhs.t0 != rhs.t0) return lhs.t0 < rhs.t0;
        if (lhs.t1 != rhs.t1) return lhs.t1 < rhs.t1;
        if (lhs.t2 != rhs.t2) return lhs.t2 < rhs.t2;
        return lhs.t3 < rhs.t3;
}

bool operator>(const T4 &lhs, const T4 &rhs)
{
        if (lhs.t0 != rhs.t0) return lhs.t0 > rhs.t0;
        if (lhs.t1 != rhs.t1) return lhs.t1 > rhs.t1;
        if (lhs.t2 != rhs.t2) return lhs.t2 > rhs.t2;
        return lhs.t3 > rhs.t3;
}

bool operator==(const T4 &lhs, const T4 &rhs)
{
        if (lhs.t0 != rhs.t0) return false;
        if (lhs.t1 != rhs.t1) return false;
        if (lhs.t2 != rhs.t2) return false;
        return lhs.t3 == rhs.t3;
}

bool operator!=(const T4 &lhs, const T4 &rhs)
{
        return !(lhs == rhs);
}

void llin(ll &a)
{
        cin >> a;
}

void llinl1(auto &v, ll count)
{
        for (ll i = 0; i < count ; ++i) {
                ll a;
                cin >> a;
                v.push_back(a);
        }
}

void llinl2(auto &v, ll count)
{
        for (ll i = 0; i < count ; ++i) {
                ll a, b;
                cin >> a >> b;
                v.push_back({a, b});
        }
}

void llinl3(auto &v, ll count)
{
        for (ll i = 0; i < count ; ++i) {
                ll a, b, c;
                cin >> a >> b >> c;
                v.push_back({a, b, c});
        }
}

void llina(auto &v, ll count)
{
        llinl1(v, count);
}

ll min(const V<ll> v)
{
        ll ret = (ll)numeric_limits<double>::infinity();
        for (auto i : v) ret = min(ret, i);
        return ret;
}

void sort(V<ll> &v)
{
        sort(v.begin(), v.end());
}

void sort_reverse(V<ll> &v)
{
        sort(v.begin(), v.end(), greater<ll>());
}

void get_divisors(V<ll> &retlist, ll x)
{
        for (int i = 1; i < sqrt(x) + 3; ++i) {
                if (x % i == 0) {
                        retlist.push_back(i);
                        retlist.push_back(x / i);
                }
        }
}

void intersection(const set<ll> &a, const set<ll> &b,
                  set<ll> &result)
{
        V<ll> resultlist;

        set_intersection(a.begin(), a.end(),
                         b.begin(), b.end(),
                         back_inserter(resultlist));

        set<ll> resultset(resultlist.begin(), resultlist.end());
        result = resultset;
}

unsigned ll combination(ll x, ll y)
{
        if (y > x / 2L) y = x - y;

        unsigned ll ret = 1;
        for (int i = 0; i < y; ++i) {
                ret *= x--;
                ret /= (i + 1);
        }

        return ret;
}

void debug_print(auto xlist)
{
        for (auto x : xlist) cout << "-- " << x << endl;
}

///////////////////////////////////////////////////////////////////////////////

ll count0[61];
ll count1[61];

ll f(ll sum, ll k, ll bit)
{
        if (bit == 0LL) {
                if (k&1LL) {
                        sum += max(count0[0], count1[0]);
                        return sum;
                }
                return sum + count1[0];
        }

        if (((k>>bit)&1LL) == 0LL) {
                sum += (1LL<<bit) * count1[bit];
                return f(sum, k, bit - 1LL);
        }

        if (((1LL<<bit)-1LL) == (k-(1LL<<bit))) {
                ll sum0 = sum + (1LL<<bit) * count1[bit];
                ll sum1 = sum + (1LL<<bit) * count0[bit];
                return f(max(sum0, sum1), (1LL<<bit)-1LL, bit - 1LL);;
        }

        // select 0
        ll sum0 = sum + (1LL<<bit) * count1[bit];
        ll ret0 = f(sum0, (1LL<<bit)-1LL, bit - 1LL);

        if (count1[bit] >= count0[bit]) return ret0;

        // select 1
        ll sum1 = sum + (1LL<<bit) * count0[bit];
        ll ret1 = f(sum1, k-(1LL<<bit), bit - 1LL);

        return max(ret0, ret1);

}

int main()
{
        ll n, k;
        llin((ll&)n); llin((ll&)k);

        V<ll> alist;
        llina(alist, n);

        rep (i, 61) count0[i] = count1[i] = 0LL;

        for (auto a : alist) {
                rep (i, 61) {
                        if ((a>>i)&1LL) count1[i]++;
                        else count0[i]++;
                }
        }

        cout << f(0LL, k, 60LL);

        return 0;
}

///////////////////////////////////////////////////////////////////////////////


Measured memory_bytes: 1400