#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include using namespace std; const int MOD=998244353; ll modpow(ll x,ll n){ ll ans=1; while(n){ if(n&1) ans=ans*x%MOD; x=x*x%MOD; n/=2; } return ans; } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); ll n,m; cin>>n>>m; vector A(n),B(m); rep(i,n) cin>>A[i]; rep(i,m) cin>>B[i]; ll a=0,b=0; rep(i,n) a^=A[i]; rep(i,m) b^=B[i]; if(a!=b){ cout<<0<