#include <bits/stdc++.h>

using namespace std;


//Ogranicenja:
//1 <= N, Q <= 5 * 10 ^ 5;
//1 <= Ai <= 10 ^ 9
//1 <= L <= R <= N

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, q; cin >> n >> q;
    vector<int> a;
    vector<int> s;


    for(int i = 0; i < n; i++){
        int p; cin >> p;
        a.push_back(p);
    }

    for (int k = 0; k < q; k++){
        int l, r; cin >> l >> r;

        for (int j = l; j < r; j++){
            if ((a[l] & a[j]) > (a[l] ^ a[j]))s.push_back(j);
            
        }
        cout << s.size() << '\n';
        s = {};
            /*
            cout << "Velicina niza: " << s.size() << '\n';
            cout << "Niz: ";
            for (int p = 0; p < s.size(); p++)cout << s[p] << " ";
            cout << '\n';
            s = {};
            */
        
    }

    

    return 0;
}