#include <bits/stdc++.h>
using namespace std;
#define maxa 1e9
int n, q;

int main()
{
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    while(q--){
        int l, r;
        cin >> l >> r;
        l--, r--;
        set<int> s;
        for (int i = l; i < r; i++) {
            for (int j = i + 1; j <= r; j++) {
                if (pow(2, log2(a[i] + a[j] + 1)) != a[i] + a[j] + 1) {
                    //cout << a[i] << " " << a[j] << endl;
                    s.insert(a[i]);
                    s.insert(a[j]);
                }
            }
        }
        if (s.size() != 0)
            cout << s.size() << endl;
        else {
            cout << 1 << endl;
        }
    }
    return 0;
}