#include<bits/stdc++.h>
#define int long long
#define ll long long
using namespace std;
const int N = 500005;
int n, m;
int a[N];
ll trie[20000005][2];
ll tot;
ll siz[20000005];
struct dat{
ll sum;
int id, rk;
friend bool operator<(dat xx, dat yy)
{
return xx.sum < yy.sum;
}
};
void insert(ll x)
{
int p = 0;//这个节点拒绝装载任何信息
for(int i = 31; i >= 0; i --)
{
int t = (x >> i) & 1ll;
siz[p] ++;
if(!trie[p][t])
{
trie[p][t] = ++tot;
}
p = trie[p][t];
}
siz[p] ++;//子树大小
}
ll query(ll x, int rk)
{
int p = 0;
ll res = 0;
for(int i = 31; i >= 0; i --)
{
int t = (x >> i) & 1ll;
if(!trie[p][!t])
{
p = trie[p][t];
}
else if(siz[trie[p][!t]] < rk)//否则只能去相同地方 一定有
{
p = trie[p][t];
rk -= siz[trie[p][!t]];
}
else
{
p = trie[p][!t];
res |= (1ll << i);
}
}
return res;
}
priority_queue<dat> q;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// cout << (1ll << 32) - 1 << endl;return 0;//共32位
cin >> n >> m;
m *= 2;
for(int i = 1; i <= n; i ++)
{
cin >> a[i];
a[i] ^= a[i - 1];
}
for(int i = 0; i <= n; i ++)
{
insert(a[i]);
}
for(int i = 0; i <= n; i ++)
{
q.push({query(a[i], 1), i, 1});
}
ll ans = 0;
for(int i = 1; i <= m; i ++)
{
dat u = q.top();
q.pop();
ans += u.sum;
if(u.rk >= n)continue;
u.rk ++;
u.sum = query(a[u.id], u.rk);
q.push(u);
}
cout << ans / 2 << endl;
return 0;
}