#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define LOG(f...) fprintf(stderr, f)
#define DBG(f...) printf("%3d: ", __LINE__), printf(f)
// #define DBG(f...) void()
#define all(cont) begin(cont), end(cont)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
template <class T> void read(T &x) {
char ch; x = 0;
int f = 1;
while (isspace(ch = getchar()));
if (ch == '-') ch = getchar(), f = -1;
do x = x * 10 + (ch - '0'); while (isdigit(ch = getchar()));
x *= f;
}
template <class T, class ...A> void read(T &x, A&... args) { read(x); read(args...); }
const double eps = 1e-9;
const int H = 1e9;
const int N = 1000005;
int lim;
int n, qc;
struct sgnf { int p, v; };
int ans[N];
vector<sgnf> A;
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
read(n, qc);
if (n <= 1000) lim = 0;
else lim = H - sqrt((1 - pow(eps, 1. / n)) * 2. * H * H) - 1;
for (int i = 0; i < n; ++i) {
int x; read(x);
if (x >= lim) A.push_back({i, x});
}
for (int i = 0; i < n + qc; ++i) {
int x; read(x);
if (i >= n) x ^= ans[i - n];
if (x >= lim) {
for (sgnf p : A) {
int t = i - p.p;
if (t >= 0 && t <= qc) ans[t] = max(ans[t], x + p.v);
}
}
if (i >= n) printf("%d\n", ans[i - n]);
}
printf("%d\n", ans[qc]);
return 0;
}