#include <bits/stdc++.h>

using namespace std;

int poredi (int A,int B){
    if (A==0 || B==0) return 0;
    else return 1;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cerr.tie(0);
    int i,N,Q,a,b;
    cin>>N>>Q;
    int A[N],S[Q];
    vector <int> C,B,V;
    for (i=0;i<N;i++)cin>>A[i];
    for (i=0;i<Q;i++){
        cin>>a>>b;a=A[a-1];b=A[b-1];
        do{
            if (a==0)C.push_back(0);
            else if (a==1){C.push_back(1);a--;}
            else {C.push_back(a%2); a/=2;}
        }while(a>0);
        do{
            if (b==0)B.push_back(0);
            else if (b==1){B.push_back(1);b--;}
            else {B.push_back(b%2); b/=2;}
        }while(b>0);
        unsigned int j=abs(C.size()-B.size());
        //cout<<j<<endl;
        if (C.size()>B.size())for (unsigned int k=0;k<j;k++)B.push_back(0);
        else if (C.size()<B.size())for (unsigned int k=0;k<j;k++)C.push_back(0);
        //for (unsigned int m=0;m<C.size();m++){cout<<C.size()<<C[m]<<" "<<B.size()<<B[m]<<endl;}
        int s=0;
        bool ok=true;
        for (unsigned int k=0;k<C.size();k++)
        {
            if (ok&&(poredi(C[k],B[k])==0))continue;
            V.push_back(poredi(C[k],B[k]));
            ok=false;
        }
        //cout<<V.size()<<endl;
        if (V.size()==0)V.push_back(0);
        //for (unsigned int m=0;m<C.size();m++){cout<<V.size()<<V[m]<<endl;}
        int z=1;
        for (unsigned int k=V.size()-1;k>=0;k++,z*=2)
        {
            s=s+V[k]*z;
        }
        S[i]=s;
        C.clear();B.clear();V.clear();
    }
    for (i=0;i<Q;i++)cout<<S[i]<<endl;
    return 0;
}