#include <bits/stdc++.h>
using namespace std;
#define int long long
// #define x first
// #define y second
#define File(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)
inline void debug() { cerr << '\n'; }
template<typename Type, typename... Other>
inline void debug(const Type& x, const Other&... y) { cerr << x << ' '; debug(y...); }
#define DEBUG(a...) cerr << "[" << #a << "] = ", debug(a);
typedef long long LL;
typedef pair<int, int> PII;
const int N = 3000010;
const int INF = 0x3f3f3f3f;
template<typename Type>
inline void read(Type &res)
{
res = 0;
int ch = getchar(), flag = 0;
while (!isdigit(ch)) flag |= ch == '-', ch = getchar();
while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
res = flag ? -res : res;
}
template<typename Type, typename... Other>
inline void read(Type &res, Other&... y) { read(res), read(y...); }
int n, m;
int a[N], b[N], ans;
int dp[N], idx[N], idy[N];
signed main()
{
read(n, m);
for (int i = 1; i <= n; i ++) read(a[i]);
for (int i = 1; i <= n; i ++) read(b[i]), b[i] += a[i];
sort(a + 1, a + 1 + n, greater<>()), sort(b + 1, b + 1 + n, greater<>());
idx[0] = idy[0] = 1;
for (int i = 0; i <= m; i ++)
{
ans ^= dp[i];
if (idx[i] <= n && dp[i] + a[idx[i]] > dp[i + 1])
dp[i + 1] = dp[i] + a[idx[i]], idx[i + 1] = idx[i] + 1, idy[i + 1] = idy[i];
if (idy[i] <= n && dp[i] + b[idy[i]] > dp[i + 2])
dp[i + 2] = dp[i] + b[idy[i]], idy[i + 2] = idy[i] + 1, idx[i + 2] = idx[i];
}
cout << ans << '\n';
}