#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
using namespace std;

int n, q, l, r, a, rez, brojac, maxx;
string res;

struct slog {
    string binarni;

}slog [100005];

int main () {

    scanf("%d %d", &n, &q);

    for (int i=1; i<=n; i++) {
        scanf("%d", &a);
        int brojac=20;
        while (brojac>=0) {
            if (a%2==0) slog[i].binarni+='0';
            else        slog[i].binarni+='1';
            a/=2;
            brojac--;
        }

    }


        for (int i=1; i<=q; i++) {

            res="111111111111111111111";
            scanf("%d %d", &l, &r);
            brojac=20;
            while (brojac>=0)  {
                for (int k=l; k<=r; k++) {
                    if (slog[k].binarni[brojac]=='0') {
                        res[brojac]='0';
                        break;
                    }
                }
                brojac--;
            }

            rez=0;
            bool nadjen=false;
            for (int k=19; k>=0; k--) {
                    if (!nadjen and res[k]=='1') {
                        rez=1;
                        nadjen=true;
                    }
                    else if (nadjen and res[k]=='0') rez*=2;
                    else if (nadjen and res[k]=='1') {
                        rez*=2;
                        rez++;
                    }
            }
            printf("%d\n", rez);

        }





    return 0;
}