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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, q, rez;
    cin>>n>>q;
    int brojevi[n];
    for(int i = 0; i < n; i ++) { cin>>brojevi[i]; }
    int upiti[q][2];

    for(int i = 0; i < q; i ++)
    { cin>>upiti[i][0]>>upiti[i][1];
        int t = upiti[i][1] - upiti[i][0] + 1;
        rez = brojevi[upiti[i][0]-1];
        for(int j = 1; j < t; j ++)
        {
            rez = rez & brojevi[upiti[i][0]+j-1];
            if(rez == 0)
                 break;
        }
        cout<<rez<<endl;
    }
    return 0;
}