#include <iostream>

int get_deg2(unsigned int a) {
    int br=0;
    while (a/2>0) {
        a/=2;
        br++;
    }
    return br;
}

int main() {
    int n, q, s, index;
    int arr[5000];
    scanf("%d%d", &n, &q);
    for (int i=0; i<n; i++) scanf("%d", &arr[i]);

    for (int i=0; i<q; i++) {
        int l, r, maximum=0;
        scanf("%d%d", &l, &r);
        l--;
        r--;

        for (int j=l; j<r; j++) {
            int br=0;
            for (int k=j+1; k<=r; k++) {
                if ((arr[j] & arr[k]) > (arr[j] ^ arr[k])) br++;
            }
            if (br>maximum) maximum=br;
        }
        printf("%d\n", maximum+1);
    }
    return 0;
}