#include <bits/stdc++.h>

using std::cout;
using std::cin;


int resenje(int *arr, int a, int b)
{
    a -= 1;
    b -= 1;

    if (b < a)
    {
        int p = a;
        a = b;
        b = p;
    }

    int res = arr[a];
    for (int i = a + 1; i <= b; i++)
        res &= arr[i];

    return res;
}


int n, q;
int temp1, temp2;

int main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);


    cin >> n >> q;
    int a[200000];
    int res[200000];

    for (int i = 0; i < n; i++)
        cin >> a[i];

    for (int i = 0; i < q; i++)
    {
        cin >> temp1 >> temp2;
        res[i] = resenje(a, temp1, temp2);
    }
    for (int i = 0; i < q; i++)
        cout << res[i] << "\n";

    return 0;
}