#include <bits/stdc++.h>

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

int resenje(int arr[], int a, int b)
{
    a--;
    b--;

    int res = arr[a] & arr[b];

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


int n, q;
int temp1, temp2;

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

    int a[200000];
    int res[200000];

    cin >> n >> q;

    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;
}