#include <bits/stdc++.h>




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);
    int a[200000];

    scanf("%d%d", &n, &q);

    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);

    for (int i = 0; i < q; i++)
    {
        scanf("%d%d", &temp1, &temp2);
        int r = resenje(a, temp1 - 1, temp2 - 1);
        printf("%d\n", r);
    }

    return 0;
}