#include<iostream>
#define MAX 100
#include<algorithm>
using namespace std;
void unos(unsigned long int a[], unsigned int n)
{
    for(int i=0;i<n;i++)
        cin>>a[i];
}
void unosq(int a[][MAX], unsigned int q)
{
    int l=2;
    for(int i=0;i<q;i++)
        for(int j=0;j<l;i++)
            cin>>a[i][j];
}
int hormutacija(unsigned long int a[], int l, int r)
{
    for(int i=l;i<=r;i++)
    {
        int br=0;
        if(a[i]&a[i+1]>a[i]^a[i+1])
            br++;
        if(a[i]&a[i]>a[i]^a[i])
            br++;
        return br;
    }
}
int main()
{
    unsigned int n,q,l,r;
    cin>>n>>q;
    unsigned long int a[n];
    int b[MAX][MAX];
    unos(a,n);
    unosq(b,q);
    for(int i=0;i<q;i++)
    {
        for(int j=b[i][0];j<b[i][1];j++)
            cout<<hormutacija(a,b[i][0],b[i][1]);
    }
    return 0;
}