#include using namespace std; using LL=long long; using ULL=unsigned long long; #define rep(i,n) for(int i=0;i<(n);i++) int N,Q; vector A; int main(){ cin>>N; A.resize(N); rep(i,N) cin>>A[i]; vector G; ULL no; { int dcrA[60]; int rA[60]; rep(i,60) rA[i]=-1; rep(i,N) rep(d,60) if((A[i]>>d)&1) rA[d]=i; pair S[61]; S[0] = {-1,-1}; rep(i,60){ S[i+1] = {rA[i],i}; } sort(S,S+61); int p=-1; rep(i,60){ if(S[i+1].first!=S[i].first) p++; dcrA[S[i+1].second]=p; } G.resize(p+1); no=0; rep(i,60){ if(dcrA[i]==-1) no |= 1ull<>Q; while(Q--){ ULL b; cin>>b; bool enable = true; int no_flipped=0; if((no&b) == 0){ no_flipped=0; } else if((no&b) == no){ no_flipped=1; } else enable=false; for(ULL g:G) if(((g&b) != g) && ((g&b) != 0)) enable=false; int flipped = 0; int ans=0; for(int i=G.size()-1; i>=0 && enable; i--){ ULL g = G[i]; int flip=1; if(g&b) flip=0; if(flipped != flip) ans++; flipped = flip; } if(no) if(ans%2 != no_flipped) { ans++; if(G.size()==N){ enable=false; } } if(!enable){ cout<<-1<