// Online IDE - Code Editor, Compiler, Interpreter
#include<iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
vector<int> v1(n);
vector<int> v2(m);
for(int i = 0; i < n; i++){
cin>>v1[i];
}
for(int j = 0; j < m; j ++){
cin>>v2[j];
}
vector<int> ans;
for(int i = 0; i < v1.size(); i++){
for(int j = 0; j < v2.size(); j++){
int x = v1[i] ^ v2[j];
ans.push_back(x);
}
}
int left=0,right = left + 1;
int final = 0;
while(right < ans.size()){
final ^= (ans[left] ^ ans[right]);
left++;
right++;
}
cout<<final<<endl;
}
Ci8vIE9ubGluZSBJREUgLSBDb2RlIEVkaXRvciwgQ29tcGlsZXIsIEludGVycHJldGVyCgojaW5jbHVkZTxpb3N0cmVhbT4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPHZlY3Rvcj4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpCnsKICAgIGludCBuLG07CiAgICBjaW4+Pm4+Pm07CiAgICB2ZWN0b3I8aW50PiB2MShuKTsKICAgIHZlY3RvcjxpbnQ+IHYyKG0pOwogICAgZm9yKGludCBpID0gMDsgaSA8IG47IGkrKyl7CiAgICAgICAgY2luPj52MVtpXTsKICAgIH0KICAgIAogICAgZm9yKGludCBqID0gMDsgaiA8IG07IGogKyspewogICAgICAgIGNpbj4+djJbal07CiAgICB9CiAgICAKICAgIHZlY3RvcjxpbnQ+IGFuczsKICAgIGZvcihpbnQgaSA9IDA7IGkgPCB2MS5zaXplKCk7IGkrKyl7CiAgICAgICAgZm9yKGludCBqID0gMDsgaiA8IHYyLnNpemUoKTsgaisrKXsKICAgICAgICAgICAgaW50IHggPSB2MVtpXSBeIHYyW2pdOwogICAgICAgICAgICBhbnMucHVzaF9iYWNrKHgpOwogICAgICAgIH0KICAgIH0KICAgIAogICBpbnQgbGVmdD0wLHJpZ2h0ID0gbGVmdCArIDE7CiAgIGludCBmaW5hbCA9IDA7CiAgIHdoaWxlKHJpZ2h0IDwgYW5zLnNpemUoKSl7CiAgIAlmaW5hbCBePSAoYW5zW2xlZnRdIF4gYW5zW3JpZ2h0XSk7CiAgIAlsZWZ0Kys7CiAgIAlyaWdodCsrOwogICB9CiAgIAogICBjb3V0PDxmaW5hbDw8ZW5kbDsKICAgCn0K