#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    int a[n];
    set<int> s;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        s.insert(a[i]);
    }


    if(n <= 10000)
    {
        while(q--)
        {
            int l, r;
            cin >> l >> r;
            int br = a[l-1];
            for(int i = l; i < r; i++)
                br &= a[i];

            cout << br << "\n";
        }
    }

    else if(s.size() < 3)
    {
        int br1[n], br0[n];
        br1[0] = br0[0] = 0;

        for(int i = 0; i < n; i++)
        {
            if(i == 0)
            {
                br1[i] = (a[i] == 1);
                br0[i] = (a[i] == 0);
            }

            else
            {
                br1[i] = (a[i] == 1) + br1[i-1];
                br0[i] = (a[i] == 0) + br0[i-1];
            }
        }

        while(q--)
        {
            int l, r;
            cin >> l >> r;
            int x;
            if(l == 1)
                x = br0[r-1];
            else
                x = br0[r-1]-br0[l-2];
            if(x > 0)
                cout << 0 << "\n";
            else
                cout << 1 << "\n";
        }
    }

    else
    {
        int b[20][n];

        for(int i = 0; i < 20; i++)
            for(int j = 0; j < n; j++)
                b[i][j] = 0;

        for(int i = 0; i < n; i++)
        {
            int x = a[i];
            vector<int> bits;
            while(x > 0)
            {
                bits.push_back(x%2);
                x /= 2;
            }

            reverse(bits.begin(), bits.end());

            for(int j = 0; j < bits.size(); j++)
            {
                b[j][i] += bits[j];
            }

            if(i > 0)
                for(int j = 0; j < 20; j++)
                    b[j][i] += b[j][i-1];
        }


        while(q--)
        {
            int l, r;
            cin >> l >> r;
            l--;
            r--;

            vector<int> brj;

            for(int i = 0; i < 20; i++)
            {
                int x;
                if(l == 0)
                    x = b[i][r];
                else
                    x = b[i][r]-b[i][l-1];
                brj.push_back((x > r-l+1));
            }

            int broj = 0;
            for(int i = 0; i < brj.size(); i++)
            {
                broj += pow(2, i)*brj[i];
            }

            cout << broj << "\n";
        }

    }


}