#include <stdio.h>

int n, q;
int temp1, temp2;

int main()
{
    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 = a[temp1 - 1];
        for (int i = temp1; i < temp2; i++)
            r &= a[i];
        printf("%d\n", r);
    }
}