#include<bits\stdc++.h>

using namespace std;

long f(long a, long b)
{
    b = 1 << (b - 1);
    a = a & b;
    return a > 0;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    long n, q;
    cin>>n>>q;
    long a[n], s[q], m[n][sizeof(long) * 8], qp[sizeof(long) * 8];
    for(int i = 0; i < sizeof(long) * 8; i++)
    {
        qp[i] = 0;
    }
    for(long i = 0; i < n; i++)
    {
        cin>>a[i];
        for(int j = 0; j < sizeof(long) * 8; j++)
        {
            qp[j] += f(a[i], j);
            m[i][j] = qp[j];
        }
    }
    for(int i = 0; i < q; i++)
    {
        long l, r;
        cin>>l>>r;
        l -= 1;
        r -= 1;
        if(l == 0)
        {
            for(int j = 0; j < sizeof(long) * 8; j++)
            {
                qp[j] = m[r][j];
            }
        }
        else
        {
            for(int j = 0; j < sizeof(long) * 8; j++)
            {
                qp[j] = m[r][j] - m[l - 1][j];
            }
        }
        for(int j = 0; j < sizeof(long) * 8; j++)
        {
            if(qp[j] > r - l)
            {
                qp[j] = 1;
            }
            else
            {
                qp[j] = 0;
            }
        }
        s[i] = 0;
        long ppp = 1;
        for(int j = 0; j < sizeof(long) * 8; j++)
        {
            s[i] += qp[j] * ppp;
            ppp *= 2;
        }
        s[i] /= 2;
    }
    for(int i = 0; i < q; i++)
    {
        cout<<s[i]<<endl;
    }
}