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

int n, q, l, r, a[200005], rez, brojac, maxx, binarni [200005][22];
string res;



int main () {

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

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

        scanf("%d", &a[i]);
        if (a[i]>maxx) maxx=a[i];
    }

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

            scanf("%d %d", &l, &r);
            rez=1;
            for (int k=l; k<=r; k++) {
                if (a[k]==0) {
                    rez=0;
                    break;
                }
            }
            printf("%d\n", rez);
        }

}
else
for (int i=1; i<=n; i++) {
        int brojac=20;
        while (a[i]>0) {
            if (a[i]%2==1) binarni[i][brojac]=1;
            a[i]/=2;
            brojac--;

        }
    }


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

            res="111111111111111111111";
            scanf("%d %d", &l, &r);

            for (brojac=20; brojac>=0; brojac--)  {
                for (int k=l; k<=r; k++) {
                    if (binarni[k][brojac]==0) {
                        res[brojac]='0';
                        break;
                    }

                }

            }


            rez=0;
            bool nadjen=false;
            for (int k=0; k<=20; 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;
}