#include<bits/stdc++.h>
#include<stdio.h>
#include<iostream>
#include<sstream>
#include<bitset>
#include<utility>
using namespace std;

#define pi1         3.1415927
#define pi2         2.0*acos(0.0)
#define pi3         acos(-1.0)
#define MOD         1000000007
#define EPS         1e-11
#define PRIME       999998727899999
#define MAX         100005
#define UMAX        9223372036854775807
#define MAXARRAY    2000002
#define imax        2147483647
#define imin        -2147483648

#define so      sizeof
#define ll      long long
#define ull     unsigned long long
#define nl      '\n'
#define xx      first
#define yy      second
#define bg      begin()
#define en      end()
#define pb      push_back
#define mp      make_pair
#define ss      stringstream

#define clr(arr) memset(arr, 0, sizeof(arr))
#define SET(arr) memset(arr, -1, sizeof(arr))

#define sf          scanf
#define si(n)       scanf("%d", &n)
#define sl(n)       scanf("%lld", &n)
#define slf(n)      scanf("%lf", &n)
#define sc(n)       scanf("%c", &n)
#define si2(x, y)   scanf("%d %d", &x, &y)
#define sl2(x, y)   scanf("%lld %lld", &x, &y)
#define slf2(x, y)  scanf("%lf %lf", &x, &y)

#define pf      printf
#define pi(n)   printf("%d\n", n)
#define pl(n)   printf("%lld\n", n)
#define plf(n)  printf("%lf\n", n)
#define pc(n)   printf("%c\n", n)

#define READ()  freopen("input.txt", "r", stdin)
#define WRITE() freopen("output.txt", "w", stdout)
#define BOOST   std::ios_base::sync_with_stdio(0);

#define FOR(i,n)       for(i=0; i<n; i++)
#define LOOP(i,j,k)    for(i=j; i<k; i++)
#define REV(i,j,k)     for(i=j; i>=k; i--)

typedef pair<int,int>   pii;
typedef pair<ll,ll>     pll;
typedef vector<int>     vi;
typedef vector<ll>      vl;
typedef vector<pii>     vii;
typedef vector<pll>     vll;
typedef stack<int>      si;
typedef stack<ll>       sl;
typedef queue<int>      qi;
typedef queue<ll>       ql;
typedef set<int>        sti;
typedef set<ll>         stl;

template<class T> T GCD(T a, T b) {while(b){b^=a^=b^=a%=b;} return a;}
template<class T> T LCM(T a, T b) {T x=(a*b)/GCD(a, b); return x;}
template<class T> T sumdigit(T n) {if (n == 0){return 0;} return (n % 10 + sumdigit(n / 10));}
template<class T> T maxarray(T *arr) {T n=sizeof(arr); T x=*max_element(arr, arr+n); return x;} ///z=maxarray(a, n)
template<class T> T minarray(T *arr) {T n=sizeof(arr); T x=*min_element(arr, arr+n); return x;} ///z=minarray(a, n)
template<class T> double triangle(T a, T b, T c) {double s, area; s=(a+b+c)/2; area=sqrt(fabs(s*(s-a)*(s-b)*(s-c))); return area;}///any datatype
double triangle(double a, double b, double c) {double s, area; s=(a+b+c)/2; area=sqrt(fabs(s*(s-a)*(s-b)*(s-c))); return area;}///double datatype
bool isprime(ll n) {if(n==2){return true;} if(n<2 || n%2==0){return false;}for(ll i=3;i*i<=n;i+=2){if(n%i==0) {return false;}} return true;}
ll bigmod(ll a,ll b) {if(b==0){return 1%MOD;} ll x=bigmod(a,b/2); x=(x*x)%MOD; if(b%2==1){x=(x*a)%MOD;} return x;}///a-base, b-power (a^b)%MOD
ll countone(ull n) {int i; ull one=1,count=0; FOR(i,64){ll bi=one;bi&=n;if(bi) count++;one<<=1;} return count;}

///Graph Directional Array [4 dir]
//ll X[4]={0,0,1,-1};
//ll Y[4]={1,-1,0,0};
///Graph Directional Array [8 dir]
//ll X[8]={0,0,1,-1,-1,1,1,-1};
//ll Y[8]={1,-1,0,0,-1,-1,1,1};
///Knight Directional Array
//ll X[8]={1, 1, 2, 2, -1, -1, -2, -2};
//ll Y[8]={2, -2, 1, -1, 2, -2, 1, -1};

int main()
{
    int n, m, l, r, ans, i, count=0, k;
    si2(n, m);
    int a[n], b[m];
    ll sum[n];
    FOR(i, n)
    {
        si(a[i]);
//        if(i==0)
//        {
//            sum[i]=a[i];
//        }
//        else if(i>0)
//        {
//            sum[i]=sum[i-1]+a[i];
//        }
        if(a[i]==1)
        {
            count++;
        }
    }
    k=min(count, n-count);
    k*=2;
    FOR(i, m)
    {
        cin>>l>>r;
//        r--;
//        l-=2;
//        if(l<0)
//        {
//            l=0;
//        }
//        ans=sum[r]-sum[l];
//        if(ans==0)
//        {
//            cout<<"1"<<nl;
//        }
//        else
//        {
//            cout<<"0"<<nl;
//        }

        cout<<((r-l)%2&&r-l<k)<<nl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<iostream>
#include<sstream>
#include<bitset>
#include<utility>
using namespace std;

#define pi1         3.1415927
#define pi2         2.0*acos(0.0)
#define pi3         acos(-1.0)
#define MOD         1000000007
#define EPS         1e-11
#define PRIME       999998727899999
#define MAX         100005
#define UMAX        9223372036854775807
#define MAXARRAY    2000002
#define imax        2147483647
#define imin        -2147483648

#define so      sizeof
#define ll      long long
#define ull     unsigned long long
#define nl      '\n'
#define xx      first
#define yy      second
#define bg      begin()
#define en      end()
#define pb      push_back
#define mp      make_pair
#define ss      stringstream

#define clr(arr) memset(arr, 0, sizeof(arr))
#define SET(arr) memset(arr, -1, sizeof(arr))

#define sf          scanf
#define si(n)       scanf("%d", &n)
#define sl(n)       scanf("%lld", &n)
#define slf(n)      scanf("%lf", &n)
#define sc(n)       scanf("%c", &n)
#define si2(x, y)   scanf("%d %d", &x, &y)
#define sl2(x, y)   scanf("%lld %lld", &x, &y)
#define slf2(x, y)  scanf("%lf %lf", &x, &y)

#define pf      printf
#define pi(n)   printf("%d\n", n)
#define pl(n)   printf("%lld\n", n)
#define plf(n)  printf("%lf\n", n)
#define pc(n)   printf("%c\n", n)

#define READ()  freopen("input.txt", "r", stdin)
#define WRITE() freopen("output.txt", "w", stdout)
#define BOOST   std::ios_base::sync_with_stdio(0);

#define FOR(i,n)       for(i=0; i<n; i++)
#define LOOP(i,j,k)    for(i=j; i<k; i++)
#define REV(i,j,k)     for(i=j; i>=k; i--)

typedef pair<int,int>   pii;
typedef pair<ll,ll>     pll;
typedef vector<int>     vi;
typedef vector<ll>      vl;
typedef vector<pii>     vii;
typedef vector<pll>     vll;
typedef stack<int>      si;
typedef stack<ll>       sl;
typedef queue<int>      qi;
typedef queue<ll>       ql;
typedef set<int>        sti;
typedef set<ll>         stl;

template<class T> T GCD(T a, T b) {while(b){b^=a^=b^=a%=b;} return a;}
template<class T> T LCM(T a, T b) {T x=(a*b)/GCD(a, b); return x;}
template<class T> T sumdigit(T n) {if (n == 0){return 0;} return (n % 10 + sumdigit(n / 10));}
template<class T> T maxarray(T *arr) {T n=sizeof(arr); T x=*max_element(arr, arr+n); return x;} ///z=maxarray(a, n)
template<class T> T minarray(T *arr) {T n=sizeof(arr); T x=*min_element(arr, arr+n); return x;} ///z=minarray(a, n)
template<class T> double triangle(T a, T b, T c) {double s, area; s=(a+b+c)/2; area=sqrt(fabs(s*(s-a)*(s-b)*(s-c))); return area;}///any datatype
double triangle(double a, double b, double c) {double s, area; s=(a+b+c)/2; area=sqrt(fabs(s*(s-a)*(s-b)*(s-c))); return area;}///double datatype
bool isprime(ll n) {if(n==2){return true;} if(n<2 || n%2==0){return false;}for(ll i=3;i*i<=n;i+=2){if(n%i==0) {return false;}} return true;}
ll bigmod(ll a,ll b) {if(b==0){return 1%MOD;} ll x=bigmod(a,b/2); x=(x*x)%MOD; if(b%2==1){x=(x*a)%MOD;} return x;}///a-base, b-power (a^b)%MOD
ll countone(ull n) {int i; ull one=1,count=0; FOR(i,64){ll bi=one;bi&=n;if(bi) count++;one<<=1;} return count;}

///Graph Directional Array [4 dir]
//ll X[4]={0,0,1,-1};
//ll Y[4]={1,-1,0,0};
///Graph Directional Array [8 dir]
//ll X[8]={0,0,1,-1,-1,1,1,-1};
//ll Y[8]={1,-1,0,0,-1,-1,1,1};
///Knight Directional Array
//ll X[8]={1, 1, 2, 2, -1, -1, -2, -2};
//ll Y[8]={2, -2, 1, -1, 2, -2, 1, -1};

int main()
{
    int n, m, l, r, ans, i, count=0, k;
    si2(n, m);
    int a[n], b[m];
    ll sum[n];
    FOR(i, n)
    {
        si(a[i]);
//        if(i==0)
//        {
//            sum[i]=a[i];
//        }
//        else if(i>0)
//        {
//            sum[i]=sum[i-1]+a[i];
//        }
//        if(a[i]==1)
//        {
//            count++;
//        }
        count=count+(a[i]==1);
    }
    k=min(count, n-count)*2;
    FOR(i, m)
    {
        cin>>l>>r;
//        r--;
//        l-=2;
//        if(l<0)
//        {
//            l=0;
//        }
//        ans=sum[r]-sum[l];
//        if(ans==0)
//        {
//            cout<<"1"<<nl;
//        }
//        else
//        {
//            cout<<"0"<<nl;
//        }

        cout<<((r-l)%2 && r-l<k)<<nl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<iostream>
#include<sstream>
#include<bitset>
#include<utility>
using namespace std;

#define pi1         3.1415927
#define pi2         2.0*acos(0.0)
#define pi3         acos(-1.0)
#define MOD         1000000007
#define EPS         1e-11
#define PRIME       999998727899999
#define MAX         100005
#define UMAX        9223372036854775807
#define MAXARRAY    2000002
#define imax        2147483647
#define imin        -2147483648

#define so      sizeof
#define ll      long long
#define ull     unsigned long long
#define nl      '\n'
#define xx      first
#define yy      second
#define bg      begin()
#define en      end()
#define pb      push_back
#define mp      make_pair
#define ss      stringstream

#define clr(arr) memset(arr, 0, sizeof(arr))
#define SET(arr) memset(arr, -1, sizeof(arr))

#define sf          scanf
#define si(n)       scanf("%d", &n)
#define sl(n)       scanf("%lld", &n)
#define slf(n)      scanf("%lf", &n)
#define sc(n)       scanf("%c", &n)
#define si2(x, y)   scanf("%d %d", &x, &y)
#define sl2(x, y)   scanf("%lld %lld", &x, &y)
#define slf2(x, y)  scanf("%lf %lf", &x, &y)

#define pf      printf
#define pi(n)   printf("%d\n", n)
#define pl(n)   printf("%lld\n", n)
#define plf(n)  printf("%lf\n", n)
#define pc(n)   printf("%c\n", n)

#define READ()  freopen("input.txt", "r", stdin)
#define WRITE() freopen("output.txt", "w", stdout)
#define BOOST   std::ios_base::sync_with_stdio(0);

#define FOR(i,n)       for(i=0; i<n; i++)
#define LOOP(i,j,k)    for(i=j; i<k; i++)
#define REV(i,j,k)     for(i=j; i>=k; i--)

typedef pair<int,int>   pii;
typedef pair<ll,ll>     pll;
typedef vector<int>     vi;
typedef vector<ll>      vl;
typedef vector<pii>     vii;
typedef vector<pll>     vll;
typedef stack<int>      si;
typedef stack<ll>       sl;
typedef queue<int>      qi;
typedef queue<ll>       ql;
typedef set<int>        sti;
typedef set<ll>         stl;

template<class T> T GCD(T a, T b) {while(b){b^=a^=b^=a%=b;} return a;}
template<class T> T LCM(T a, T b) {T x=(a*b)/GCD(a, b); return x;}
template<class T> T sumdigit(T n) {if (n == 0){return 0;} return (n % 10 + sumdigit(n / 10));}
template<class T> T maxarray(T *arr) {T n=sizeof(arr); T x=*max_element(arr, arr+n); return x;} ///z=maxarray(a, n)
template<class T> T minarray(T *arr) {T n=sizeof(arr); T x=*min_element(arr, arr+n); return x;} ///z=minarray(a, n)
template<class T> double triangle(T a, T b, T c) {double s, area; s=(a+b+c)/2; area=sqrt(fabs(s*(s-a)*(s-b)*(s-c))); return area;}///any datatype
double triangle(double a, double b, double c) {double s, area; s=(a+b+c)/2; area=sqrt(fabs(s*(s-a)*(s-b)*(s-c))); return area;}///double datatype
bool isprime(ll n) {if(n==2){return true;} if(n<2 || n%2==0){return false;}for(ll i=3;i*i<=n;i+=2){if(n%i==0) {return false;}} return true;}
ll bigmod(ll a,ll b) {if(b==0){return 1%MOD;} ll x=bigmod(a,b/2); x=(x*x)%MOD; if(b%2==1){x=(x*a)%MOD;} return x;}///a-base, b-power (a^b)%MOD
ll countone(ull n) {int i; ull one=1,count=0; FOR(i,64){ll bi=one;bi&=n;if(bi) count++;one<<=1;} return count;}
//
/////Graph Directional Array [4 dir]
////ll X[4]={0,0,1,-1};
////ll Y[4]={1,-1,0,0};
/////Graph Directional Array [8 dir]
////ll X[8]={0,0,1,-1,-1,1,1,-1};
////ll Y[8]={1,-1,0,0,-1,-1,1,1};
/////Knight Directional Array
////ll X[8]={1, 1, 2, 2, -1, -1, -2, -2};
////ll Y[8]={2, -2, 1, -1, 2, -2, 1, -1};
//
//
//
//int main()
//{
//    ll n, m, l, r, ans, i, count=0, k, minus=0, plus=0, j, u=0, c=0;
////    si2(n, m);
////    ll a[n], b[m];
////    ll sum[n];
////    for(i=0;i<n;i++)
////    {
////        cin>>a[i];
//////        if(i==0)
//////        {
//////            sum[i]=a[i];
//////        }
//////        else if(i>0)
//////        {
//////            sum[i]=sum[i-1]+a[i];
//////        }
//////        if(a[i]==1)
//////        {
//////            count++;
//////        }
//////        count=count+(a[i]==1);
//////        if(a[i]<0)
//////        {
//////            minus++;
//////        }
//////        else if(a[i]>0)
//////        {
//////            plus++;
//////        }
////        k+=(l==1);
////    }
////    k=min(k, n-k)*2;
////    for(i=0;i<m;i++)
////    {
////        cin>>l>>r;
//////        r--;
//////        l-=2;
//////        if(l<0)
//////        {
//////            l=0;
//////        }
//////        ans=sum[r]-sum[l];
//////        if(ans==0)
//////        {
//////            cout<<"1"<<nl;
//////        }
//////        else
//////        {
//////            cout<<"0"<<nl;
//////        }
//////        ans=r-l+1;
//////        if((ans>minus)||(ans%2==1))
//////        {
//////           cout<<'0'<<nl;
//////        }
//////        else
//////        {
//////            cout<<'1'<<nl;
//////        }
////        cout<<((r-l)%2 && r-l<k)<<nl;
////    }
////    return 0;
////}
//
//    cin>>n>>m;
//    for(i=0;i<n;i++)
//    {
//        si(j);
//        if(j<0)
//        {
//            c++;
//        }
//        else
//        {
//            u++;
//        }
//    }
//    if(c>u)
//    {
//        c=u;
//    }
//    c=c*2;
//    for(i=0;i<m;i++)
//    {
//        cin>>u>>j;
//        u=j-u+1;
//        if((u>c)||(u%2==1))
//        {
//            cout<<"0"<<nl;
//        }
//        else
//        {
//            cout<<"1"<<nl;
//        }
//    }
//    return 0;
//}

long long i,j,u,c,n,m;
int main()
{
    si2(n, m);
    for(i=0;i<n;i++)
    {
        si(j);
        if(j<0)
        {
            c++;
        }
        else
        {
            u++;
        }
    }
    if(c>u)
    {
        c=u;
    }
    c=c*2;
    for(i=0;i<m;i++)
    {
        si2(u, j);
        u=j-u+1;
        if((u>c)||(u%2==1))
        {
            printf("0\n");
        }
        else
        {
            printf("1\n");
        }
    }
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<iostream>
#include<sstream>
#include<bitset>
#include<utility>
using namespace std;

#define pi1         3.1415927
#define pi2         2.0*acos(0.0)
#define pi3         acos(-1.0)
#define MOD         1000000007
#define EPS         1e-11
#define PRIME       999998727899999
#define MAX         100005
#define UMAX        9223372036854775807
#define MAXARRAY    2000002
#define imax        2147483647
#define imin        -2147483648

#define so      sizeof
#define ll      long long
#define ull     unsigned long long
#define nl      '\n'
#define xx      first
#define yy      second
#define bg      begin()
#define en      end()
#define pb      push_back
#define mp      make_pair
#define ss      stringstream

#define clr(arr) memset(arr, 0, sizeof(arr))
#define SET(arr) memset(arr, -1, sizeof(arr))

#define sf          scanf
#define si(n)       scanf("%d", &n)
#define sl(n)       scanf("%lld", &n)
#define slf(n)      scanf("%lf", &n)
#define sc(n)       scanf("%c", &n)
#define si2(x, y)   scanf("%d %d", &x, &y)
#define sl2(x, y)   scanf("%lld %lld", &x, &y)
#define slf2(x, y)  scanf("%lf %lf", &x, &y)

#define pf      printf
#define pi(n)   printf("%d\n", n)
#define pl(n)   printf("%lld\n", n)
#define plf(n)  printf("%lf\n", n)
#define pc(n)   printf("%c\n", n)

#define READ()  freopen("input.txt", "r", stdin)
#define WRITE() freopen("output.txt", "w", stdout)
#define BOOST   std::ios_base::sync_with_stdio(0);

#define FOR(i,n)       for(i=0; i<n; i++)
#define LOOP(i,j,k)    for(i=j; i<k; i++)
#define REV(i,j,k)     for(i=j; i>=k; i--)

typedef pair<int,int>   pii;
typedef pair<ll,ll>     pll;
typedef vector<int>     vi;
typedef vector<ll>      vl;
typedef vector<pii>     vii;
typedef vector<pll>     vll;
typedef stack<int>      si;
typedef stack<ll>       sl;
typedef queue<int>      qi;
typedef queue<ll>       ql;
typedef set<int>        sti;
typedef set<ll>         stl;

template<class T> T GCD(T a, T b) {while(b){b^=a^=b^=a%=b;} return a;}
template<class T> T LCM(T a, T b) {T x=(a*b)/GCD(a, b); return x;}
template<class T> T sumdigit(T n) {if (n == 0){return 0;} return (n % 10 + sumdigit(n / 10));}
template<class T> T maxarray(T *arr) {T n=sizeof(arr); T x=*max_element(arr, arr+n); return x;} ///z=maxarray(a, n)
template<class T> T minarray(T *arr) {T n=sizeof(arr); T x=*min_element(arr, arr+n); return x;} ///z=minarray(a, n)
template<class T> double triangle(T a, T b, T c) {double s, area; s=(a+b+c)/2; area=sqrt(fabs(s*(s-a)*(s-b)*(s-c))); return area;}///any datatype
double triangle(double a, double b, double c) {double s, area; s=(a+b+c)/2; area=sqrt(fabs(s*(s-a)*(s-b)*(s-c))); return area;}///double datatype
bool isprime(ll n) {if(n==2){return true;} if(n<2 || n%2==0){return false;}for(ll i=3;i*i<=n;i+=2){if(n%i==0) {return false;}} return true;}
ll bigmod(ll a,ll b) {if(b==0){return 1%MOD;} ll x=bigmod(a,b/2); x=(x*x)%MOD; if(b%2==1){x=(x*a)%MOD;} return x;}///a-base, b-power (a^b)%MOD
ll countone(ull n) {int i; ull one=1,count=0; FOR(i,64){ll bi=one;bi&=n;if(bi) count++;one<<=1;} return count;}

///Graph Directional Array [4 dir]
//ll X[4]={0,0,1,-1};
//ll Y[4]={1,-1,0,0};
///Graph Directional Array [8 dir]
//ll X[8]={0,0,1,-1,-1,1,1,-1};
//ll Y[8]={1,-1,0,0,-1,-1,1,1};
///Knight Directional Array
//ll X[8]={1, 1, 2, 2, -1, -1, -2, -2};
//ll Y[8]={2, -2, 1, -1, 2, -2, 1, -1};
long i,j,u,c,n,m;
int main(){
 scanf("%ld %ld",&n,&m);
 for(i=0;i<n;i++){
  scanf("%ld",&j);
  if(j<0)
    c++;
  else
    u++;
 }
 if(c>u)
    c=u;
 c=c*2;
 for(i=0;i<m;i++){
  scanf("%ld %ld",&u,&j);
  u=j-u+1;
  if((u>c)||(u%2==1))
    printf("0\n");
  else
    printf("1\n");
 }
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<iostream>
#include<sstream>
#include<bitset>
#include<utility>
using namespace std;

#define pi1         3.1415927
#define pi2         2.0*acos(0.0)
#define pi3         acos(-1.0)
#define MOD         1000000007
#define EPS         1e-11
#define PRIME       999998727899999
#define MAX         100005
#define UMAX        9223372036854775807
#define MAXARRAY    2000002
#define imax        2147483647
#define imin        -2147483648

#define so      sizeof
#define ll      long long
#define ull     unsigned long long
#define nl      '\n'
#define xx      first
#define yy      second
#define bg      begin()
#define en      end()
#define pb      push_back
#define mp      make_pair
#define ss      stringstream

#define clr(arr) memset(arr, 0, sizeof(arr))
#define SET(arr) memset(arr, -1, sizeof(arr))

#define sf          scanf
#define si(n)       scanf("%d", &n)
#define sl(n)       scanf("%lld", &n)
#define slf(n)      scanf("%lf", &n)
#define sc(n)       scanf("%c", &n)
#define si2(x, y)   scanf("%d %d", &x, &y)
#define sl2(x, y)   scanf("%lld %lld", &x, &y)
#define slf2(x, y)  scanf("%lf %lf", &x, &y)

#define pf      printf
#define pi(n)   printf("%d\n", n)
#define pl(n)   printf("%lld\n", n)
#define plf(n)  printf("%lf\n", n)
#define pc(n)   printf("%c\n", n)

#define READ()  freopen("input.txt", "r", stdin)
#define WRITE() freopen("output.txt", "w", stdout)
#define BOOST   std::ios_base::sync_with_stdio(0);

#define FOR(i,n)       for(i=0; i<n; i++)
#define LOOP(i,j,k)    for(i=j; i<k; i++)
#define REV(i,j,k)     for(i=j; i>=k; i--)

typedef pair<int,int>   pii;
typedef pair<ll,ll>     pll;
typedef vector<int>     vi;
typedef vector<ll>      vl;
typedef vector<pii>     vii;
typedef vector<pll>     vll;
typedef stack<int>      si;
typedef stack<ll>       sl;
typedef queue<int>      qi;
typedef queue<ll>       ql;
typedef set<int>        sti;
typedef set<ll>         stl;

template<class T> T GCD(T a, T b) {while(b){b^=a^=b^=a%=b;} return a;}
template<class T> T LCM(T a, T b) {T x=(a*b)/GCD(a, b); return x;}
template<class T> T sumdigit(T n) {if (n == 0){return 0;} return (n % 10 + sumdigit(n / 10));}
template<class T> T maxarray(T *arr) {T n=sizeof(arr); T x=*max_element(arr, arr+n); return x;} ///z=maxarray(a, n)
template<class T> T minarray(T *arr) {T n=sizeof(arr); T x=*min_element(arr, arr+n); return x;} ///z=minarray(a, n)
template<class T> double triangle(T a, T b, T c) {double s, area; s=(a+b+c)/2; area=sqrt(fabs(s*(s-a)*(s-b)*(s-c))); return area;}///any datatype
double triangle(double a, double b, double c) {double s, area; s=(a+b+c)/2; area=sqrt(fabs(s*(s-a)*(s-b)*(s-c))); return area;}///double datatype
bool isprime(ll n) {if(n==2){return true;} if(n<2 || n%2==0){return false;}for(ll i=3;i*i<=n;i+=2){if(n%i==0) {return false;}} return true;}
ll bigmod(ll a,ll b) {if(b==0){return 1%MOD;} ll x=bigmod(a,b/2); x=(x*x)%MOD; if(b%2==1){x=(x*a)%MOD;} return x;}///a-base, b-power (a^b)%MOD
ll countone(ull n) {int i; ull one=1,count=0; FOR(i,64){ll bi=one;bi&=n;if(bi) count++;one<<=1;} return count;}
//
/////Graph Directional Array [4 dir]
////ll X[4]={0,0,1,-1};
////ll Y[4]={1,-1,0,0};
/////Graph Directional Array [8 dir]
////ll X[8]={0,0,1,-1,-1,1,1,-1};
////ll Y[8]={1,-1,0,0,-1,-1,1,1};
/////Knight Directional Array
////ll X[8]={1, 1, 2, 2, -1, -1, -2, -2};
////ll Y[8]={2, -2, 1, -1, 2, -2, 1, -1};
//
//
//
//int main()
//{
//    ll n, m, l, r, ans, i, count=0, k, minus=0, plus=0, j, u=0, c=0;
////    si2(n, m);
////    ll a[n], b[m];
////    ll sum[n];
////    for(i=0;i<n;i++)
////    {
////        cin>>a[i];
//////        if(i==0)
//////        {
//////            sum[i]=a[i];
//////        }
//////        else if(i>0)
//////        {
//////            sum[i]=sum[i-1]+a[i];
//////        }
//////        if(a[i]==1)
//////        {
//////            count++;
//////        }
//////        count=count+(a[i]==1);
//////        if(a[i]<0)
//////        {
//////            minus++;
//////        }
//////        else if(a[i]>0)
//////        {
//////            plus++;
//////        }
////        k+=(l==1);
////    }
////    k=min(k, n-k)*2;
////    for(i=0;i<m;i++)
////    {
////        cin>>l>>r;
//////        r--;
//////        l-=2;
//////        if(l<0)
//////        {
//////            l=0;
//////        }
//////        ans=sum[r]-sum[l];
//////        if(ans==0)
//////        {
//////            cout<<"1"<<nl;
//////        }
//////        else
//////        {
//////            cout<<"0"<<nl;
//////        }
//////        ans=r-l+1;
//////        if((ans>minus)||(ans%2==1))
//////        {
//////           cout<<'0'<<nl;
//////        }
//////        else
//////        {
//////            cout<<'1'<<nl;
//////        }
////        cout<<((r-l)%2 && r-l<k)<<nl;
////    }
////    return 0;
////}
//
//    cin>>n>>m;
//    for(i=0;i<n;i++)
//    {
//        si(j);
//        if(j<0)
//        {
//            c++;
//        }
//        else
//        {
//            u++;
//        }
//    }
//    if(c>u)
//    {
//        c=u;
//    }
//    c=c*2;
//    for(i=0;i<m;i++)
//    {
//        cin>>u>>j;
//        u=j-u+1;
//        if((u>c)||(u%2==1))
//        {
//            cout<<"0"<<nl;
//        }
//        else
//        {
//            cout<<"1"<<nl;
//        }
//    }
//    return 0;
//}

long long i,j,u,c,n,m;
int main()
{
    cin>>n>>m;
    for(i=0;i<n;i++)
    {
        cin>>j;
        if(j<0)
        {
            c++;
        }
        else
        {
            u++;
        }
    }
    if(c>u)
    {
        c=u;
    }
    c=c*2;
    for(i=0;i<m;i++)
    {
        cin>>u>>j;
        u=j-u+1;
        if((u>c)||(u%2==1))
        {
            printf("0\n");
        }
        else
        {
            printf("1\n");
        }
    }
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<iostream>
#include<sstream>
#include<bitset>
#include<utility>
using namespace std;

#define pi1         3.1415927
#define pi2         2.0*acos(0.0)
#define pi3         acos(-1.0)
#define MOD         1000000007
#define EPS         1e-11
#define PRIME       999998727899999
#define MAX         100005
#define UMAX        9223372036854775807
#define MAXARRAY    2000002
#define imax        2147483647
#define imin        -2147483648

#define so      sizeof
#define ll      long long
#define ull     unsigned long long
#define nl      '\n'
#define xx      first
#define yy      second
#define bg      begin()
#define en      end()
#define pb      push_back
#define mp      make_pair
#define ss      stringstream

#define clr(arr) memset(arr, 0, sizeof(arr))
#define SET(arr) memset(arr, -1, sizeof(arr))

#define sf          scanf
#define si(n)       scanf("%d", &n)
#define sl(n)       scanf("%lld", &n)
#define slf(n)      scanf("%lf", &n)
#define sc(n)       scanf("%c", &n)
#define si2(x, y)   scanf("%d %d", &x, &y)
#define sl2(x, y)   scanf("%lld %lld", &x, &y)
#define slf2(x, y)  scanf("%lf %lf", &x, &y)

#define pf      printf
#define pi(n)   printf("%d\n", n)
#define pl(n)   printf("%lld\n", n)
#define plf(n)  printf("%lf\n", n)
#define pc(n)   printf("%c\n", n)

#define READ()  freopen("input.txt", "r", stdin)
#define WRITE() freopen("output.txt", "w", stdout)
#define BOOST   std::ios_base::sync_with_stdio(0);

#define FOR(i,n)       for(i=0; i<n; i++)
#define LOOP(i,j,k)    for(i=j; i<k; i++)
#define REV(i,j,k)     for(i=j; i>=k; i--)

typedef pair<int,int>   pii;
typedef pair<ll,ll>     pll;
typedef vector<int>     vi;
typedef vector<ll>      vl;
typedef vector<pii>     vii;
typedef vector<pll>     vll;
typedef stack<int>      si;
typedef stack<ll>       sl;
typedef queue<int>      qi;
typedef queue<ll>       ql;
typedef set<int>        sti;
typedef set<ll>         stl;

template<class T> T GCD(T a, T b) {while(b){b^=a^=b^=a%=b;} return a;}
template<class T> T LCM(T a, T b) {T x=(a*b)/GCD(a, b); return x;}
template<class T> T sumdigit(T n) {if (n == 0){return 0;} return (n % 10 + sumdigit(n / 10));}
template<class T> T maxarray(T *arr) {T n=sizeof(arr); T x=*max_element(arr, arr+n); return x;} ///z=maxarray(a, n)
template<class T> T minarray(T *arr) {T n=sizeof(arr); T x=*min_element(arr, arr+n); return x;} ///z=minarray(a, n)
template<class T> double triangle(T a, T b, T c) {double s, area; s=(a+b+c)/2; area=sqrt(fabs(s*(s-a)*(s-b)*(s-c))); return area;}///any datatype
double triangle(double a, double b, double c) {double s, area; s=(a+b+c)/2; area=sqrt(fabs(s*(s-a)*(s-b)*(s-c))); return area;}///double datatype
bool isprime(ll n) {if(n==2){return true;} if(n<2 || n%2==0){return false;}for(ll i=3;i*i<=n;i+=2){if(n%i==0) {return false;}} return true;}
ll bigmod(ll a,ll b) {if(b==0){return 1%MOD;} ll x=bigmod(a,b/2); x=(x*x)%MOD; if(b%2==1){x=(x*a)%MOD;} return x;}///a-base, b-power (a^b)%MOD
ll countone(ull n) {int i; ull one=1,count=0; FOR(i,64){ll bi=one;bi&=n;if(bi) count++;one<<=1;} return count;}

///Graph Directional Array [4 dir]
//ll X[4]={0,0,1,-1};
//ll Y[4]={1,-1,0,0};
///Graph Directional Array [8 dir]
//ll X[8]={0,0,1,-1,-1,1,1,-1};
//ll Y[8]={1,-1,0,0,-1,-1,1,1};
///Knight Directional Array
//ll X[8]={1, 1, 2, 2, -1, -1, -2, -2};
//ll Y[8]={2, -2, 1, -1, 2, -2, 1, -1};

int main()
{
    ll n, m, l, r, ans, i, count=0, k, minus=0, plus=0;
    si2(n, m);
    ll a[n], b[m];
    ll sum[n];
    FOR(i, n)
    {
        si(a[i]);
//        if(i==0)
//        {
//            sum[i]=a[i];
//        }
//        else if(i>0)
//        {
//            sum[i]=sum[i-1]+a[i];
//        }
//        if(a[i]==1)
//        {
//            count++;
//        }
//        count=count+(a[i]==1);
        if(a[i]<0)
        {
            minus++;
        }
        else if(a[i]>0)
        {
            puls++;
        }
    }
    if(minus>plus)
    {
        count=plus;
    }
    else
    {
        count=minus;
    }
    count*=2;
    FOR(i, m)
    {
        cin>>l>>r;
//        r--;
//        l-=2;
//        if(l<0)
//        {
//            l=0;
//        }
//        ans=sum[r]-sum[l];
//        if(ans==0)
//        {
//            cout<<"1"<<nl;
//        }
//        else
//        {
//            cout<<"0"<<nl;
//        }
        ans=r-l+1;
        if((ans>count)||(ans%2==1))
        {
           cout<<'0'<<nl;
        }
        else
        {
            cout<<'1'<<nl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<iostream>
#include<sstream>
#include<bitset>
#include<utility>
using namespace std;

#define pi1         3.1415927
#define pi2         2.0*acos(0.0)
#define pi3         acos(-1.0)
#define MOD         1000000007
#define EPS         1e-11
#define PRIME       999998727899999
#define MAX         100005
#define UMAX        9223372036854775807
#define MAXARRAY    2000002
#define imax        2147483647
#define imin        -2147483648

#define so      sizeof
#define ll      long long
#define ull     unsigned long long
#define nl      '\n'
#define xx      first
#define yy      second
#define bg      begin()
#define en      end()
#define pb      push_back
#define mp      make_pair
#define ss      stringstream

#define clr(arr) memset(arr, 0, sizeof(arr))
#define SET(arr) memset(arr, -1, sizeof(arr))

#define sf          scanf
#define si(n)       scanf("%d", &n)
#define sl(n)       scanf("%lld", &n)
#define slf(n)      scanf("%lf", &n)
#define sc(n)       scanf("%c", &n)
#define si2(x, y)   scanf("%d %d", &x, &y)
#define sl2(x, y)   scanf("%lld %lld", &x, &y)
#define slf2(x, y)  scanf("%lf %lf", &x, &y)

#define pf      printf
#define pi(n)   printf("%d\n", n)
#define pl(n)   printf("%lld\n", n)
#define plf(n)  printf("%lf\n", n)
#define pc(n)   printf("%c\n", n)

#define READ()  freopen("input.txt", "r", stdin)
#define WRITE() freopen("output.txt", "w", stdout)
#define BOOST   std::ios_base::sync_with_stdio(0);

#define FOR(i,n)       for(i=0; i<n; i++)
#define LOOP(i,j,k)    for(i=j; i<k; i++)
#define REV(i,j,k)     for(i=j; i>=k; i--)

typedef pair<int,int>   pii;
typedef pair<ll,ll>     pll;
typedef vector<int>     vi;
typedef vector<ll>      vl;
typedef vector<pii>     vii;
typedef vector<pll>     vll;
typedef stack<int>      si;
typedef stack<ll>       sl;
typedef queue<int>      qi;
typedef queue<ll>       ql;
typedef set<int>        sti;
typedef set<ll>         stl;

template<class T> T GCD(T a, T b) {while(b){b^=a^=b^=a%=b;} return a;}
template<class T> T LCM(T a, T b) {T x=(a*b)/GCD(a, b); return x;}
template<class T> T sumdigit(T n) {if (n == 0){return 0;} return (n % 10 + sumdigit(n / 10));}
template<class T> T maxarray(T *arr) {T n=sizeof(arr); T x=*max_element(arr, arr+n); return x;} ///z=maxarray(a, n)
template<class T> T minarray(T *arr) {T n=sizeof(arr); T x=*min_element(arr, arr+n); return x;} ///z=minarray(a, n)
template<class T> double triangle(T a, T b, T c) {double s, area; s=(a+b+c)/2; area=sqrt(fabs(s*(s-a)*(s-b)*(s-c))); return area;}///any datatype
double triangle(double a, double b, double c) {double s, area; s=(a+b+c)/2; area=sqrt(fabs(s*(s-a)*(s-b)*(s-c))); return area;}///double datatype
bool isprime(ll n) {if(n==2){return true;} if(n<2 || n%2==0){return false;}for(ll i=3;i*i<=n;i+=2){if(n%i==0) {return false;}} return true;}
ll bigmod(ll a,ll b) {if(b==0){return 1%MOD;} ll x=bigmod(a,b/2); x=(x*x)%MOD; if(b%2==1){x=(x*a)%MOD;} return x;}///a-base, b-power (a^b)%MOD
ll countone(ull n) {int i; ull one=1,count=0; FOR(i,64){ll bi=one;bi&=n;if(bi) count++;one<<=1;} return count;}

///Graph Directional Array [4 dir]
//ll X[4]={0,0,1,-1};
//ll Y[4]={1,-1,0,0};
///Graph Directional Array [8 dir]
//ll X[8]={0,0,1,-1,-1,1,1,-1};
//ll Y[8]={1,-1,0,0,-1,-1,1,1};
///Knight Directional Array
//ll X[8]={1, 1, 2, 2, -1, -1, -2, -2};
//ll Y[8]={2, -2, 1, -1, 2, -2, 1, -1};

int main()
{
    ll n, m, l, r, ans, i, count=0, k, minus=0, plus=0, j, u=0, c=0;
//    si2(n, m);
//    ll a[n], b[m];
//    ll sum[n];
//    for(i=0;i<n;i++)
//    {
//        cin>>a[i];
////        if(i==0)
////        {
////            sum[i]=a[i];
////        }
////        else if(i>0)
////        {
////            sum[i]=sum[i-1]+a[i];
////        }
////        if(a[i]==1)
////        {
////            count++;
////        }
////        count=count+(a[i]==1);
////        if(a[i]<0)
////        {
////            minus++;
////        }
////        else if(a[i]>0)
////        {
////            plus++;
////        }
//        k+=(l==1);
//    }
//    k=min(k, n-k)*2;
//    for(i=0;i<m;i++)
//    {
//        cin>>l>>r;
////        r--;
////        l-=2;
////        if(l<0)
////        {
////            l=0;
////        }
////        ans=sum[r]-sum[l];
////        if(ans==0)
////        {
////            cout<<"1"<<nl;
////        }
////        else
////        {
////            cout<<"0"<<nl;
////        }
////        ans=r-l+1;
////        if((ans>minus)||(ans%2==1))
////        {
////           cout<<'0'<<nl;
////        }
////        else
////        {
////            cout<<'1'<<nl;
////        }
//        cout<<((r-l)%2 && r-l<k)<<nl;
//    }
//    return 0;
//}

    cin>>n>>m;
    for(i=0;i<n;i++)
    {
        si(j);
        if(j<0)
        {
            c++;
        }
        else
        {
            u++;
        }
    }
    if(c>u)
    {
        c=u;
    }
    c=c*2;
    for(i=0;i<m;i++)
    {
        cin>>u>>j;
        u=j-u+1;
        if((u>c)||(u%2==1))
        {
            cout<<"0"<<nl;
        }
        else
        {
            cout<<"1"<<nl;
        }
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
	int n,m,l,r,k=0;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>l;
		k+=(l==1);
	}
	k=min(k,n-k)*2;
	for(int i=0;i<m;i++)
	{
		cin>>l>>r;
		cout<< ((r-l)%2 && r-l<k)<<endl;
	}
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<iostream>
#include<sstream>
#include<bitset>
#include<utility>
using namespace std;

#define pi1         3.1415927
#define pi2         2.0*acos(0.0)
#define pi3         acos(-1.0)
#define MOD         1000000007
#define EPS         1e-11
#define PRIME       999998727899999
#define MAX         100005
#define UMAX        9223372036854775807
#define MAXARRAY    2000002
#define imax        2147483647
#define imin        -2147483648

#define so      sizeof
#define ll      long long
#define ull     unsigned long long
#define nl      '\n'
#define xx      first
#define yy      second
#define bg      begin()
#define en      end()
#define pb      push_back
#define mp      make_pair
#define ss      stringstream

#define clr(arr) memset(arr, 0, sizeof(arr))
#define SET(arr) memset(arr, -1, sizeof(arr))

#define sf          scanf
#define si(n)       scanf("%d", &n)
#define sl(n)       scanf("%lld", &n)
#define slf(n)      scanf("%lf", &n)
#define sc(n)       scanf("%c", &n)
#define si2(x, y)   scanf("%d %d", &x, &y)
#define sl2(x, y)   scanf("%lld %lld", &x, &y)
#define slf2(x, y)  scanf("%lf %lf", &x, &y)

#define pf      printf
#define pi(n)   printf("%d\n", n)
#define pl(n)   printf("%lld\n", n)
#define plf(n)  printf("%lf\n", n)
#define pc(n)   printf("%c\n", n)

#define READ()  freopen("input.txt", "r", stdin)
#define WRITE() freopen("output.txt", "w", stdout)
#define BOOST   std::ios_base::sync_with_stdio(0);

#define FOR(i,n)       for(i=0; i<n; i++)
#define LOOP(i,j,k)    for(i=j; i<k; i++)
#define REV(i,j,k)     for(i=j; i>=k; i--)

typedef pair<int,int>   pii;
typedef pair<ll,ll>     pll;
typedef vector<int>     vi;
typedef vector<ll>      vl;
typedef vector<pii>     vii;
typedef vector<pll>     vll;
typedef stack<int>      si;
typedef stack<ll>       sl;
typedef queue<int>      qi;
typedef queue<ll>       ql;
typedef set<int>        sti;
typedef set<ll>         stl;

template<class T> T GCD(T a, T b) {while(b){b^=a^=b^=a%=b;} return a;}
template<class T> T LCM(T a, T b) {T x=(a*b)/GCD(a, b); return x;}
template<class T> T sumdigit(T n) {if (n == 0){return 0;} return (n % 10 + sumdigit(n / 10));}
template<class T> T maxarray(T *arr) {T n=sizeof(arr); T x=*max_element(arr, arr+n); return x;} ///z=maxarray(a, n)
template<class T> T minarray(T *arr) {T n=sizeof(arr); T x=*min_element(arr, arr+n); return x;} ///z=minarray(a, n)
template<class T> double triangle(T a, T b, T c) {double s, area; s=(a+b+c)/2; area=sqrt(fabs(s*(s-a)*(s-b)*(s-c))); return area;}///any datatype
double triangle(double a, double b, double c) {double s, area; s=(a+b+c)/2; area=sqrt(fabs(s*(s-a)*(s-b)*(s-c))); return area;}///double datatype
bool isprime(ll n) {if(n==2){return true;} if(n<2 || n%2==0){return false;}for(ll i=3;i*i<=n;i+=2){if(n%i==0) {return false;}} return true;}
ll bigmod(ll a,ll b) {if(b==0){return 1%MOD;} ll x=bigmod(a,b/2); x=(x*x)%MOD; if(b%2==1){x=(x*a)%MOD;} return x;}///a-base, b-power (a^b)%MOD
ll countone(ull n) {int i; ull one=1,count=0; FOR(i,64){ll bi=one;bi&=n;if(bi) count++;one<<=1;} return count;}

///Graph Directional Array [4 dir]
//ll X[4]={0,0,1,-1};
//ll Y[4]={1,-1,0,0};
///Graph Directional Array [8 dir]
//ll X[8]={0,0,1,-1,-1,1,1,-1};
//ll Y[8]={1,-1,0,0,-1,-1,1,1};
///Knight Directional Array
//ll X[8]={1, 1, 2, 2, -1, -1, -2, -2};
//ll Y[8]={2, -2, 1, -1, 2, -2, 1, -1};

int main()
{
    int n, m, l, r, ans, i, count=0, k;
    si2(n, m);
    int a[n], b[m];
    ll sum[n];
    FOR(i, n)
    {
        si(a[i]);
//        if(i==0)
//        {
//            sum[i]=a[i];
//        }
//        else if(i>0)
//        {
//            sum[i]=sum[i-1]+a[i];
//        }
        if(a[i]==1)
        {
            count++;
        }
    }
    k=min(count, n-count)*2;
    FOR(i, m)
    {
        cin>>l>>r;
//        r--;
//        l-=2;
//        if(l<0)
//        {
//            l=0;
//        }
//        ans=sum[r]-sum[l];
//        if(ans==0)
//        {
//            cout<<"1"<<nl;
//        }
//        else
//        {
//            cout<<"0"<<nl;
//        }

        cout<<((r-l)%2 && r-l<k)<<nl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include<stdio.h>
#include<iostream>
#include<sstream>
#include<bitset>
#include<utility>
using namespace std;

#define pi1         3.1415927
#define pi2         2.0*acos(0.0)
#define pi3         acos(-1.0)
#define MOD         1000000007
#define EPS         1e-11
#define PRIME       999998727899999
#define MAX         100005
#define UMAX        9223372036854775807
#define MAXARRAY    2000002
#define imax        2147483647
#define imin        -2147483648

#define so      sizeof
#define ll      long long
#define ull     unsigned long long
#define nl      '\n'
#define xx      first
#define yy      second
#define bg      begin()
#define en      end()
#define pb      push_back
#define mp      make_pair
#define ss      stringstream

#define clr(arr) memset(arr, 0, sizeof(arr))
#define SET(arr) memset(arr, -1, sizeof(arr))

#define sf          scanf
#define si(n)       scanf("%d", &n)
#define sl(n)       scanf("%lld", &n)
#define slf(n)      scanf("%lf", &n)
#define sc(n)       scanf("%c", &n)
#define si2(x, y)   scanf("%d %d", &x, &y)
#define sl2(x, y)   scanf("%lld %lld", &x, &y)
#define slf2(x, y)  scanf("%lf %lf", &x, &y)

#define pf      printf
#define pi(n)   printf("%d\n", n)
#define pl(n)   printf("%lld\n", n)
#define plf(n)  printf("%lf\n", n)
#define pc(n)   printf("%c\n", n)

#define READ()  freopen("input.txt", "r", stdin)
#define WRITE() freopen("output.txt", "w", stdout)
#define BOOST   std::ios_base::sync_with_stdio(0);

#define FOR(i,n)       for(i=0; i<n; i++)
#define LOOP(i,j,k)    for(i=j; i<k; i++)
#define REV(i,j,k)     for(i=j; i>=k; i--)

typedef pair<int,int>   pii;
typedef pair<ll,ll>     pll;
typedef vector<int>     vi;
typedef vector<ll>      vl;
typedef vector<pii>     vii;
typedef vector<pll>     vll;
typedef stack<int>      si;
typedef stack<ll>       sl;
typedef queue<int>      qi;
typedef queue<ll>       ql;
typedef set<int>        sti;
typedef set<ll>         stl;

template<class T> T GCD(T a, T b) {while(b){b^=a^=b^=a%=b;} return a;}
template<class T> T LCM(T a, T b) {T x=(a*b)/GCD(a, b); return x;}
template<class T> T sumdigit(T n) {if (n == 0){return 0;} return (n % 10 + sumdigit(n / 10));}
template<class T> T maxarray(T *arr) {T n=sizeof(arr); T x=*max_element(arr, arr+n); return x;} ///z=maxarray(a, n)
template<class T> T minarray(T *arr) {T n=sizeof(arr); T x=*min_element(arr, arr+n); return x;} ///z=minarray(a, n)
template<class T> double triangle(T a, T b, T c) {double s, area; s=(a+b+c)/2; area=sqrt(fabs(s*(s-a)*(s-b)*(s-c))); return area;}///any datatype
double triangle(double a, double b, double c) {double s, area; s=(a+b+c)/2; area=sqrt(fabs(s*(s-a)*(s-b)*(s-c))); return area;}///double datatype
bool isprime(ll n) {if(n==2){return true;} if(n<2 || n%2==0){return false;}for(ll i=3;i*i<=n;i+=2){if(n%i==0) {return false;}} return true;}
ll bigmod(ll a,ll b) {if(b==0){return 1%MOD;} ll x=bigmod(a,b/2); x=(x*x)%MOD; if(b%2==1){x=(x*a)%MOD;} return x;}///a-base, b-power (a^b)%MOD
ll countone(ull n) {int i; ull one=1,count=0; FOR(i,64){ll bi=one;bi&=n;if(bi) count++;one<<=1;} return count;}

///Graph Directional Array [4 dir]
//ll X[4]={0,0,1,-1};
//ll Y[4]={1,-1,0,0};
///Graph Directional Array [8 dir]
//ll X[8]={0,0,1,-1,-1,1,1,-1};
//ll Y[8]={1,-1,0,0,-1,-1,1,1};
///Knight Directional Array
//ll X[8]={1, 1, 2, 2, -1, -1, -2, -2};
//ll Y[8]={2, -2, 1, -1, 2, -2, 1, -1};

int main()
{
    ll n, m, l, r, ans, i, count=0, k, minus=0, plus=0, j, u, c;
//    si2(n, m);
//    ll a[n], b[m];
//    ll sum[n];
//    for(i=0;i<n;i++)
//    {
//        cin>>a[i];
////        if(i==0)
////        {
////            sum[i]=a[i];
////        }
////        else if(i>0)
////        {
////            sum[i]=sum[i-1]+a[i];
////        }
////        if(a[i]==1)
////        {
////            count++;
////        }
////        count=count+(a[i]==1);
////        if(a[i]<0)
////        {
////            minus++;
////        }
////        else if(a[i]>0)
////        {
////            plus++;
////        }
//        k+=(l==1);
//    }
//    k=min(k, n-k)*2;
//    for(i=0;i<m;i++)
//    {
//        cin>>l>>r;
////        r--;
////        l-=2;
////        if(l<0)
////        {
////            l=0;
////        }
////        ans=sum[r]-sum[l];
////        if(ans==0)
////        {
////            cout<<"1"<<nl;
////        }
////        else
////        {
////            cout<<"0"<<nl;
////        }
////        ans=r-l+1;
////        if((ans>minus)||(ans%2==1))
////        {
////           cout<<'0'<<nl;
////        }
////        else
////        {
////            cout<<'1'<<nl;
////        }
//        cout<<((r-l)%2 && r-l<k)<<nl;
//    }
//    return 0;
//}

    cin>>n>>m;
    for(i=0;i<n;i++)
    {
        si(j);
        if(j<0)
        {
            c++;
        }
        else
        {
            u++;
        }
    }
    if(c>u)
    {
        c=u;
    }
    c=c*2;
    for(i=0;i<m;i++)
    {
        cin>>u>>j;
        u=j-u+1;
        if((u>c)||(u%2==1))
        {
            cout<<"0"<<nl;
        }
        else
        {
            cout<<"1"<<nl;
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stack>
#include <queue>
#include <string.h>
#include <cstdlib>
#include <stdio.h>
#include <sstream>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main()
{
//freopen("input.txt","r",stdin);
std::ios::sync_with_stdio(false);
int64_t i , j, k=0 , m , n,o=0,v=0,vv,oo=0;
cin >> n>>m;
int64_t a[n];
n++;
int64_t x,xx,y,yy,tx,ty;
x=y=0;
for(i=1;i<n;i++)
{
    cin >> a[i];
if(a[i]==-1)
    x++;
    else
        y++;
    }
int64_t ww,w;
vector<int64_t>q;
for(i=0;i<m;i++)
{
cin >> w >> ww;
o = (ww-w)+1;
//cout << o << endl;
int h = o/2;
if(o%2==0 && x>=h && y>=h && o!=0 && o!=1)
    q.push_back(1);
else
    q.push_back(0);
}

for(i=0;i<m;i++)
{
    cout << q[i] << endl;
}
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stack>
#include <queue>
#include <string.h>
#include <cstdlib>
#include <stdio.h>
#include <sstream>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main()
{
//freopen("input.txt","r",stdin);
int64_t i , j, k=0 , m , n,o=0,v=0,vv,oo=0;
cin >> n>>m;
int64_t a[n];
n++;
int64_t x,xx,y,yy,tx,ty;
x=y=0;
for(i=1;i<n;i++)
{
    cin >> a[i];
if(a[i]==-1)
    x++;
    else
        y++;
    }
int64_t ww,w;
vector<int64_t>q;
for(i=0;i<m;i++)
{
cin >> w >> ww;
o = ww-w;
o++;
if(o%2!=0 && o!=0)
    q.push_back(0);
else if(o%2==0  && o!=0 && x>=o/2 && y>=o/2)
    q.push_back(1);
else
    q.push_back(0);

}
for(i=0;i<q.size();i++)
{
    cout << q[i] << endl;
}
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stack>
#include <queue>
#include <string.h>
#include <cstdlib>
#include <stdio.h>
#include <sstream>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main()
{
//freopen("input.txt","r",stdin);
int i , j, k=0 , m , n,o=0,v=0,vv,oo=0;
cin >> n>>m;
int a[n];
n++;
int x,xx,y,yy,tx,ty;
x=y=0;
for(i=1;i<n;i++)
{
    cin >> a[i];
if(a[i]==-1)
    x++;
    else
        y++;
    }
int ww,w;
vector<int>q;
for(i=0;i<m;i++)
{
cin >> w >> ww;
o = ww-w;
o++;
//cout << o << endl;
if(o%2!=0 && o!=0)
    q.push_back(0);
else
{
    q.push_back(1);
}

}
for(i=0;i<q.size();i++)
{
    cout << q[i] << endl;
}
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stack>
#include <queue>
#include <string.h>
#include <cstdlib>
#include <stdio.h>
#include <sstream>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main()
{
//freopen("input.txt","r",stdin);
int64_t i , j, k=0 , m , n,o=0,v=0,vv,oo=0;
cin >> n>>m;
int64_t a[n];
n++;
int64_t x,xx,y,yy,tx,ty;
x=y=0;
for(i=1;i<n;i++)
{
    cin >> a[i];
if(a[i]==-1)
    x++;
    else
        y++;
    }
int64_t ww,w;
vector<int64_t>q;
for(i=0;i<m;i++)
{
cin >> w >> ww;
o = (ww-w)+1;
//cout << o << endl;
int h = o/2;
if(o%2==0 && x>=h && y>=h && o!=0 && o!=1)
    q.push_back(1);
else
    q.push_back(0);
}

for(i=0;i<m;i++)
{
    cout << q[i] << endl;
}
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stack>
#include <queue>
#include <string.h>
#include <cstdlib>
#include <stdio.h>
#include <sstream>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main()
{
//freopen("input.txt","r",stdin);
int64_t i , j, k=0 , m , n,o=0,v=0,vv,oo=0;
cin >> n>>m;
int64_t a[n];
n++;
int64_t x,xx,y,yy,tx,ty;
x=y=0;
for(i=1;i<n;i++)
{
    cin >> a[i];
if(a[i]==-1)
    x++;
    else
        y++;
    }
int64_t ww,w;
vector<int64_t>q;
for(i=0;i<m;i++)
{
cin >> w >> ww;
o = ww-w;
o++;
//cout << o << endl;
if(o%2!=0 && o!=0)
    q.push_back(0);
else if(x>=o/2 && y>=o/2)
{
    q.push_back(1);
}
else
    q.push_back(0);
}

for(i=0;i<m;i++)
{
    cout << q[i] << endl;
}
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stack>
#include <queue>
#include <string.h>
#include <cstdlib>
#include <stdio.h>
#include <sstream>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main()
{
//freopen("input.txt","r",stdin);
int i , j, k=0 , m , n,o=0,v=0,vv,oo=0;
cin >> n>>m;
int a[n];
n++;
int x,xx,y,yy,tx,ty;
x=y=0;
for(i=1;i<n;i++)
{
    cin >> a[i];
if(a[i]==-1)
    x++;
    else
        y++;
    }
int ww,w;
vector<int>q;
for(i=0;i<m;i++)
{
cin >> w >> ww;
o = ww-w;
o++;
//cout << o << endl;
if(o%2!=0 && o!=0)
    q.push_back(0);
else if(x>=o/2 && y>=o/2)
{
    q.push_back(1);
}
else
    q.push_back(0);

}
for(i=0;i<q.size();i++)
{
    cout << q[i] << endl;
}
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stack>
#include <queue>
#include <string.h>
#include <cstdlib>
#include <stdio.h>
#include <sstream>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main()
{
//freopen("input.txt","r",stdin);
int64_t i , j, k=0 , m , n,o=0,v=0,vv,oo=0;
cin >> n>>m;
int64_t a[n];
n++;
int64_t x,xx,y,yy,tx,ty;
x=y=0;
for(i=1;i<n;i++)
{
    cin >> a[i];
if(a[i]==-1)
    x++;
    else
        y++;
    }
int64_t ww,w;
vector<int64_t>q;
for(i=0;i<m;i++)
{
cin >> w >> ww;
o = ww-w;
o++;
//cout << o << endl;
int h = o/2;
if(o%2==0 && x>0 && y>0)
    q.push_back(1);
else
    q.push_back(0);
}

for(i=0;i<m;i++)
{
    cout << q[i] << endl;
}
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stack>
#include <queue>
#include <string.h>
#include <cstdlib>
#include <stdio.h>
#include <sstream>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main()
{
//freopen("input.txt","r",stdin);
int64_t i , j, k=0 , m , n,o=0,v=0,vv,oo=0;
cin >> n>>m;
int64_t a[n];
n++;
int64_t x,xx,y,yy,tx,ty;
x=y=0;
for(i=1;i<n;i++)
{
    cin >> a[i];
if(a[i]==-1)
    x++;
    else
        y++;
    }
int64_t ww,w;
vector<int64_t>q;
for(i=0;i<m;i++)
{
cin >> w >> ww;
o = ww-w;
o++;
//cout << o << endl;
int h = o/2;
if(x>=h && y>=h && o!=0 && o!=1)
{
    q.push_back(1);
}
else
    q.push_back(0);
}

for(i=0;i<m;i++)
{
    cout << q[i] << endl;
}
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stack>
#include <queue>
#include <string.h>
#include <cstdlib>
#include <stdio.h>
#include <sstream>
#include <vector>
#include <set>
#include <map>
using namespace std;

int main()
{
//freopen("input.txt","r",stdin);
int64_t i , j, k=0 , m , n,o=0,v=0,vv,oo=0;
cin >> n>>m;
int64_t a[n];
int64_t b[m][2];
n++;
int64_t x,xx,y,yy,tx,ty;
x=y=0;
for(i=1;i<n;i++)
{
    cin >> a[i];
if(a[i]==-1)
    x++;
    else
        y++;
    }
int64_t ww,w;
vector<int64_t>q;
for(i=0;i<m;i++)
{
cin >> b[i][0] >> b[i][1];
}
for(i=0;i<m;i++)
{
    w = b[i][0];
    ww = b[i][1];
    o = ww-w;
o++;
//cout << o << endl;
if(o%2!=0 && o!=0)
     cout << 0 << endl;
else if(x>=o/2 && y>=o/2)
{
    cout << 1 << endl;
}
else
   cout << 0 << endl;
}

    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int c = 0, n, m, l, r, s, a;

    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        if (a == 1)
            c++;
    }
    if (c>n / 2)
        c = n - c;
    for (int i = 0; i < m; i++)
    {
        cin >> l >> r;
        s = r - l + 1;
        if (s % 2 == 0 && s / 2 <= c)
            cout << 1;
        else
            cout << 0;
    }

}


#include<iostream>
using namespace std;
int main()
{
    int c = 0, n, m, l, r, s, a;

    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        if (a == 1)
            c++;
    }
    if (c>n / 2)
        c = n - c;
    for (int i = 0; i < m; i++)
    {
        cin >> l >> r;
        s = r - l + 1;
        if (s % 2 == 0 && s / 2 <= c)
            cout << 1<<"\n";
        else
            cout << 0 << "\n";
    }

}


#include<iostream>
using namespace std;
int main()
{
    int c = 0, n, m, l, r, s, a;
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        if (a == -1)
            c++;
    }
    if (c>n / 2)
        c = n - c;
    for (int i = 0; i < m; i++)
    {
        cin >> l >> r;
        if ((r - l + 1) % 2 == 0 && (r - l + 1) / 2 <= c)
            cout << 1<<"\n";
        else
            cout << 0 << "\n";;
    }
}


#include<iostream>
using namespace std;
int fun1(int n)
{
    int a;
    if (n == 0)
            return 0;
    else
    {
        cin >> a;
        if (a == -1)
            return 1 + fun1(n - 1);
        else
            return 0 + fun1(n - 1);
    }
}

int fun2(int m,int c)
{
    int l,r,s;
    if (m == 0)
        return 0;
    else
    {
        cin >>l>>r ;
        s = r - l + 1;
        if (s%2 == 0&&s<=c)
            cout<< 1 ;
        else
            cout << 0;
        return fun2(m - 1, c);
    }
}

int main()
{
    int c , n, m, l, r, s, a;
    cin >> n >> m;
    c = fun1(n);
    if (c>n / 2)
        c = n - c;
    fun2(m, c);

}


#include<iostream>
using namespace std;
int main()
{
    int c = 0, n, m, l, r, s, a;

    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        if (a == -1)
            c++;
    }
    if (c>n / 2)
        c = n - c;
    for (int i = 0; i < m; i++)
    {
        cin >> l >> r;
        s = r - l + 1;
        if (r % 2 == l % 2)
            cout << 0 << "\n";
        else if (s / 2 <= c)
            cout << 1 << "\n";
        else
            cout << 0 << "\n";
    }

}


#include<iostream>
using namespace std;
int fun1(int n)
{
    int a;
    if (n == 0)
            return 0;
    else
    {
        cin >> a;
        if (a == -1)
            return 1 + fun1(n - 1);
        else
            return 0 + fun1(n - 1);
    }
}

void fun2(int m,int c)
{
    int l,r,s;
    if (m == 0)
        exit(0);
    else
    {
        cin >>l>>r ;
        s = r - l + 1;
        if (s%2 == 0&&s/2<=c)
            cout<< 1<<"\n" ;
        else
            cout << 0<<"\n";
        return fun2(m - 1, c);
    }
}

int main()
{
    int c , n, m, l, r, s, a;
    cin >> n >> m;
    c = fun1(n);
    if (c>n / 2)
        c = n - c;
    fun2(m, c);

}


# include<stdio.h>
using namespace std;
int main()
{
    int c = 0, n, m, l, r, s, a;

   scanf("%d%d",&n,&m);
    for (int i = 0; i < n; i++)
    {
        scanf("%d",&a);
        if (a == -1)
            c++;
    }
    if (c>n / 2)
        c = n - c;
    for (int i = 0; i < m; i++)
    {
        scanf("%d%d",&l,&r);
        s = r - l + 1;
        if (s / 2 <= c&&s % 2 == 0 )
            printf("1\n") ;
        else
            printf("0\n" ) ;
    }

}


#include<iostream>
using namespace std;
int main()
{
    int c = 0, n, m, l, r, s, a;
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        if (a == -1)
            c++;
    }
    if (c>n / 2)
        c = n - c;
    for (int i = 0; i < m; i++)
    {
        cin >> l >> r;
        if (l % 2 != r % 2){
            s = (r - l + 1) / 2;
            if (s <= c)
                cout << 1 << "\n";
            else
                cout << 0 << "\n";
        }
        else
            cout << 0 << "\n";
    }
}


# include<stdio.h>
using namespace std;
int main()
{
    int c = 0, n, m, l, r, s, a;

   scanf("%d%d",&n,&m);
    for (int i = 0; i < n; i++)
    {
        scanf("%d",&a);
        if (a == -1)
            c++;
    }
    if (c>n / 2)
        c = n - c;
    for (int i = 0; i < m; i++)
    {
        scanf("%d%d",&l,&r);
        s = r - l + 1;
        if (s / 2 <= c&&s % 2 == 0 )
            printf("1") ;
        else
            printf("0" ) ;
    }

}


#include<iostream>
using namespace std;
int fun1(int n)
{
    int a;
    if (n == 0)
            return 0;
    else
    {
        cin >> a;
        if (a == -1)
            return 1 + fun1(n - 1);
        else
            return 0 + fun1(n - 1);
    }
}

int fun2(int m,int c)
{
    int l,r,s;
    if (m == 0)
        return 0;
    else
    {
        cin >>l>>r ;
        s = r - l + 1;
        if (s%2 == 0&&s/2<=c)
            cout<< 1<<"\n" ;
        else
            cout << 0<<"\n";
        return fun2(m - 1, c);
    }
}

int main()
{
    int c , n, m, l, r, s, a;
    cin >> n >> m;
    c = fun1(n);
    if (c>n / 2)
        c = n - c;
    fun2(m, c);

}


#include<iostream>
using namespace std;
int main()
{
    int c = 0, n, m, l, r, s, a;

    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        if (a == -1)
            c++;
    }
    if (c>n / 2)
        c = n - c;
    for (int i = 0; i < m; i++)
    {
        cin >> l >> r;
        s = r - l + 1;
        if (s / 2 <= c&&s % 2 == 0 )
            cout << 1<<"\n";
        else
            cout << 0 << "\n";
    }

}


#include <bits/stdc++.h>
//#include <fstream>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#define P_ M_PI
#define MAXN 100009
#define INF 1000000009
#define LLINF 1000000000000000009
#define mp(x,y) make_pair(x,y)
#define ff first
#define cs(x,y) cout<<" Case "<<y<<":"<<x;
#define ss second
#define all(x) x.begin(),x.end()
#define pb(x) push_back(x)
#define ppb(x) pop_back()
using namespace std;

//ifstream cin("file.in");
//ofstream cout("file.out");

int n,m,a[300009],pl,mn,br,ik,b[300009],q;

int main()
{

cin>>n>>m;

for(int i=1;i<=n;i++){
scanf("%d",&a[i]);

    if(a[i]==-1) mn++;

    else pl++;
}

for(int i=1;i<=m;i++){
scanf("%d%d",&br,&ik);
    if(br==ik) b[i]=0;

    else if((ik-br+1)%2!=0)  b[i]=0;

    else if((ik-br+1)%2==0 && (ik-br+1)/2<=pl && (ik-br+1)/2<=mn) b[i]=1;
}

for(int i=1;i<=m;i++)
printf("%d\n",b[i]);
return 0;
}


#include <bits/stdc++.h>
//#include <fstream>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#define P_ M_PI
#define MAXN 100009
#define INF 1000000009
#define LLINF 1000000000000000009
#define mp(x,y) make_pair(x,y)
#define ff first
#define cs(x,y) cout<<" Case "<<y<<":"<<x;
#define ss second
#define all(x) x.begin(),x.end()
#define pb(x) push_back(x)
#define ppb(x) pop_back()
using namespace std;

//ifstream cin("file.in");
//ofstream cout("file.out");

int n,m,a[300009],pl,mn,br,ik,b[300009],q;

int main()
{

cin>>n>>m;

for(int i=1;i<=n;i++){
scanf("%d",a[i]);

    if(a[i]==-1) mn++;

    else pl++;
}

for(int i=1;i<=m;i++){
scanf("%d%d",&br,&iki);
    if(br==ik) b[i]=0;

    else if((ik-br+1)%2!=0)  b[i]=0;

    else if((ik-br+1)%2==0 && (ik-br+1)/2<=pl && (ik-br+1)/2<=mn) b[i]=1;
}

for(int i=1;i<=m;i++)
printf("%d\n",b[i])
return 0;
}


#include <bits/stdc++.h>
//#include <fstream>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#define P_ M_PI
#define MAXN 100009
#define INF 1000000009
#define LLINF 1000000000000000009
#define mp(x,y) make_pair(x,y)
#define ff first
#define cs(x,y) cout<<" Case "<<y<<":"<<x;
#define ss second
#define all(x) x.begin(),x.end()
#define pb(x) push_back(x)
#define ppb(x) pop_back()
using namespace std;

//ifstream cin("file.in");
//ofstream cout("file.out");

int n,m,a[300009],pl,mn,br,ik,b[300009],q;

int main()
{

cin>>n>>m;

for(int i=1;i<=n;i++){
cin>>a[i];

    if(a[i]==-1) mn++;

    else pl++;
}

for(int i=1;i<=m;i++){
cin>>br>>ik;
    if(br==ik) b[i]=0;

    else if((ik-br+1)%2!=0)  b[i]=0;

    else if((ik-br+1)%2==0 && (ik-br+1)/2<=pl && (ik-br+1)/2<=mn) b[i]=1;
}

for(int i=1;i<=m;i++)
cout<<b[i]<<endl;
return 0;
}


//#include <fstream>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <iomanip>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#define MAXN 100009
#define INF 1000000007
#define LLINF 1000000000000000007
#define mp(x,y) make_pair(x,y)
#define ff first
#define cs(x,y) cout<<"Case "<<y<<": "<<x<<endl;
#define ss second
#define all(x) x.begin(),x.end()
#define pb(x) push_back(x)
#define ppb() pop_back()
#define tr(i, c) for(typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define fr(i) for(int i=1;i<=a;i++)
/*
ifstream cin("file.in");
ofstream cout("file.out");
*/
using namespace std;

int a , b ;

int e , f ;

int main()
{

	cin >> a >> b ;
	vector < int > v ;
	int c , d  , g;
	for(int i = 0 ; i < a ; i ++ )
	{
		cin >> g ;
		if(g == - 1)
		f ++ ;
		else
		e ++ ;
	}
	for(int i = 0 ; i < b ; i ++ )
	{
			cin >> c >> d ;
			if((c - d + 1) % 2 == 0)
			{
				if((c - d + 1) / 2 <= f  and (c - d + 1) / 2 <= e)
				{
					v.push_back( 1 ) ;
				}
				else
				v.push_back( 0 ) ;
			}
			else
			v.push_back( 0 ) ;
	}
	for(int i = 0 ; i < v.size() ; i ++ )
	cout << v[ i ] << endl ;

return 0;
}


//#include<bits/stdc++.h>
//#include <fstream>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#define P_ M_PI
#define MAXN 100009
#define INF 1000000007
#define LLINF 1000000000000000007
#define mp(x,y) make_pair(x,y)
#define ff first
#define cs(x,y) cout<<"Case "<<y<<": "<<x<<endl;
#define ss second
#define all(x) x.begin(),x.end()
#define pb(x) push_back(x)
#define ppb() pop_back()
#define tr(i, c) for(typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
using namespace std;
/*
ifstream cin("file.in");
ofstream cout("file.out");
*/
int main()
{
	int n,m,arr[10009],a=0,b=0,x,y,yer[10009];
	cin>>n>>m;

	for(int i=1;i<=n;i++)
	{
		cin>>arr[i];
		if(arr[i]==-1)	a++;
		else b++;
	}

	for(int i=1;i<=m;i++)
	{
		cin>>x>>y;
		if(x==y)	yer[i]=0;

		else if((y-x+1)%2!=0)	yer[i]=0;

		else
		{
			if(a>=(y-x+1)/2 and a>=(y-x+1)/2)
				yer[i]=1;
			else
				yer[i]=0;
		}
	}

	for(int i=1;i<=m;i++)
	{
		cout<<yer[i]<<endl;
	}

return 0;
}


#include <bits/stdc++.h>
//#include <fstream>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#define P_ M_PI
#define MAXN 100009
#define INF 1000000009
#define LLINF 1000000000000000009
#define mp(x,y) make_pair(x,y)
#define ff first
#define cs(x,y) cout<<" Case "<<y<<":"<<x;
#define ss second
#define all(x) x.begin(),x.end()
#define pb(x) push_back(x)
#define ppb(x) pop_back()
using namespace std;

//ifstream cin("file.in");
//ofstream cout("file.out");

int n,m,a[300009],pl,mn,br,ik,b[300009],q;

int main()
{

cin>>n>>m;

for(int i=1;i<=n;i++){
scanf("%d",a[i]);

    if(a[i]==-1) mn++;

    else pl++;
}

for(int i=1;i<=m;i++){
scanf("%d%d",&br,&ik);
    if(br==ik) b[i]=0;

    else if((ik-br+1)%2!=0)  b[i]=0;

    else if((ik-br+1)%2==0 && (ik-br+1)/2<=pl && (ik-br+1)/2<=mn) b[i]=1;
}

for(int i=1;i<=m;i++)
printf("%d\n",b[i]);
return 0;
}


#include <iostream>
using namespace std;
int main ()
{
	int a,s=0,l,r,n,m;

	cin>>n>>m;

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

	(s<0)?s*=-1:s=s;

	for (int i=0; i<m; i++)
	{
		cin>>l>>r;
		if (r!=1 && (r-l+1)%2==0 && n-s>=r-l+1)
			cout<<1<<endl;
		else
			cout<<0<<endl;
	}

	return 0;
}


#include <iostream>
using namespace std;
int main ()
{
	long long a,neg=0,pos=0,l,r,n,m;

	cin>>n>>m;

	for (long long i=0; i<n; i++)
	{
		cin>>a;

		(a==1)?pos++:neg++;
	}

	for (long long i=0; i<m; i++)
	{
		cin>>l>>r;

		if ((r-l)%2!=0 && pos>=(r-l+1)/2 && neg>=(r-l+1)/2)
			cout<<1<<endl;

		else
			cout<<0<<endl;
	}

	return 0;
}


 #include <cstdio>

int main(){
  int n,m,z=0;std::scanf("%d%d",&n,&m);
  for(int a,i=0;i<n;++i)std::scanf("%d",&a),z+=a<0;
  if(z>n-z)z=n-z;
  for(int l,r;std::scanf("%d%d",&l,&r)==2;)
    printf("%d\n",(r-l)%2&&(r-l+1)/2<=z);
}


#include <iostream>
#include <algorithm>
using namespace std;
int main ()
{
	int a,s=0,l,r,n,m;

	cin>>n>>m;

	for (int i=0; i<n; i++)
	{
		cin>>a;
		(a==1)?s+=a:s=s;
	}

	s=min (s,n-s)*2;

	for (int i=0; i<m; i++)
	{
		cin>>l>>r;
		if ((r-l+1)%2==0 && r-l<s)
			cout<<1<<endl;
		else
			cout<<0<<endl;
	}

	return 0;
}


import java.util.*;

/**
 * User: Aphrodite
 * Date: 12-2-21
 * Time: AM12:11
 */

public class T152B {
  public static void main(String[] args) {
    new T152B().solve();
  }

  public void solve() {
    Scanner in = new Scanner(System.in);
    int n = in.nextInt(), m = in.nextInt(), x = in.nextInt(), y = in.nextInt();
    int k = in.nextInt();
    long res = 0;
    for (int i = 0; i < k; i++) {
      int dx = in.nextInt(), dy = in.nextInt();
      int t = check(x, y, dx, dy, n, m);
//      System.out.println(t);
      res += t;
      x += dx * t;
      y += dy * t;
//      System.out.println(x + " " + y);
    }
    System.out.println(res);
  }

  int check(int x, int y, int dx, int dy, int n, int m) {
    int p = 0, q = 0;
    if (dx > 0) {
      p = (n - x) / dx;
    } else if (dx < 0) {
      p = (x - 1) / -dx;
    } else {
      p = Integer.MAX_VALUE;
    }
    if (dy > 0) {
      q = (m - y) / dy;
    } else if (dy < 0) {
      q = (y - 1) / -dy;
    } else {
      q = Integer.MAX_VALUE;
    }
    return Math.min(p, q);
  }
}


import java.util.*;

/**
 * Created by IntelliJ IDEA.
 * User: piyushd
 * Date: 3/26/11
 * Time: 10:53 PM
 * To change this template use File | Settings | File Templates.
 */
public class TaskB {

    void run() {
        int n = nextInt(), m = nextInt();
        int sx = nextInt(), sy = nextInt();
        int k = nextInt();
        int[] dx = new int[k];
        int[] dy = new int[k];
        for(int i = 0; i < k; i++) {
            dx[i] = nextInt();
            dy[i] = nextInt();
        }

        long ans = 0;
        long curx = sx, cury = sy;
        for(int i = 0; i < k; i++) {
            long steps = Long.MAX_VALUE;

            if(dx[i] > 0) {
                steps = Math.min(steps, (m - curx) / dx[i]);
            } else if(dx[i] < 0) {
                steps = Math.min(steps, (curx - 1) / Math.abs(dx[i]));
            }

            if(dy[i] > 0) {
                steps = Math.min(steps, (n - cury) / dy[i]);
            } else if(dy[i] < 0) {
                steps = Math.min(steps, (cury - 1) / Math.abs(dy[i]));
            }

            curx += steps * dx[i];
            cury += steps * dy[i];
            ans += steps;
        }

        System.out.println(ans);
    }

    int nextInt(){
        try{
            int c = System.in.read();
            if(c == -1) return c;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return c;
            }
            if(c == '-') return -nextInt();
            int res = 0;
            do{
                res *= 10;
                res += c - '0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    long nextLong(){
        try{
            int c = System.in.read();
            if(c == -1) return -1;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return -1;
            }
            if(c == '-') return -nextLong();
            long res = 0;
            do{
                res *= 10;
                res += c-'0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    double nextDouble(){
        return Double.parseDouble(next());
    }

    String next(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(Character.isWhitespace(c))
                c = System.in.read();
            do{
                res.append((char)c);
            }while(!Character.isWhitespace(c=System.in.read()));
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    String nextLine(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(c == '\r' || c == '\n')
                c = System.in.read();
            do{
                res.append((char)c);
                c = System.in.read();
            }while(c != '\r' && c != '\n');
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    public static void main(String[] args){
        new TaskB().run();
    }
}


import java.util.*;

/**
 * Created by IntelliJ IDEA.
 * User: piyushd
 * Date: 3/26/11
 * Time: 10:53 PM
 * To change this template use File | Settings | File Templates.
 */
public class TaskB {

    void run() {
        int n = nextInt(), m = nextInt();
        int sx = nextInt(), sy = nextInt();
        int k = nextInt();
        int[] dx = new int[k];
        int[] dy = new int[k];
        for(int i = 0; i < k; i++) {
            dx[i] = nextInt();
            dy[i] = nextInt();
        }

        long ans = 0;
        int curx = sx, cury = sy;
        for(int i = 0; i < k; i++) {
            int steps = Integer.MAX_VALUE;

            if(dx[i] > 0) {
                steps = Math.min(steps, (m - curx) / dx[i]);
            } else if(dx[i] < 0) {
                steps = Math.min(steps, (1 - curx) / dx[i]);
            }

            if(dy[i] > 0) {
                steps = Math.min(steps, (n - cury) / dy[i]);
            } else if(dy[i] < 0) {
                steps = Math.min(steps, (1 - cury) / dy[i]);
            }

            curx += steps * dx[i];
            cury += steps * dy[i];
            ans += steps;
        }

        System.out.println(ans);
    }

    int nextInt(){
        try{
            int c = System.in.read();
            if(c == -1) return c;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return c;
            }
            if(c == '-') return -nextInt();
            int res = 0;
            do{
                res *= 10;
                res += c - '0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    long nextLong(){
        try{
            int c = System.in.read();
            if(c == -1) return -1;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return -1;
            }
            if(c == '-') return -nextLong();
            long res = 0;
            do{
                res *= 10;
                res += c-'0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    double nextDouble(){
        return Double.parseDouble(next());
    }

    String next(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(Character.isWhitespace(c))
                c = System.in.read();
            do{
                res.append((char)c);
            }while(!Character.isWhitespace(c=System.in.read()));
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    String nextLine(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(c == '\r' || c == '\n')
                c = System.in.read();
            do{
                res.append((char)c);
                c = System.in.read();
            }while(c != '\r' && c != '\n');
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    public static void main(String[] args){
        new TaskB().run();
    }
}


import java.util.*;

/**
 * Created by IntelliJ IDEA.
 * User: piyushd
 * Date: 3/26/11
 * Time: 10:53 PM
 * To change this template use File | Settings | File Templates.
 */
public class TaskB {

    void run() {
        int n = nextInt(), m = nextInt();
        int sx = nextInt(), sy = nextInt();
        int k = nextInt();
        int[] dx = new int[k];
        int[] dy = new int[k];
        for(int i = 0; i < k; i++) {
            dx[i] = nextInt();
            dy[i] = nextInt();
        }

        long ans = 0;
        int curx = sx, cury = sy;
        for(int i = 0; i < k; i++) {
            int steps = Integer.MAX_VALUE;

            if(dx[i] > 0) {
                steps = Math.min(steps, (n - curx) / dx[i]);
            } else if(dx[i] < 0) {
                steps = Math.min(steps, (1 - curx) / dx[i]);
            }

            if(dy[i] > 0) {
                steps = Math.min(steps, (m - cury) / dy[i]);
            } else if(dy[i] < 0) {
                steps = Math.min(steps, (1 - cury) / dy[i]);
            }

            curx += steps * dx[i];
            cury += steps * dy[i];
            ans += steps;
        }

        System.out.println(ans);
    }

    int nextInt(){
        try{
            int c = System.in.read();
            if(c == -1) return c;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return c;
            }
            if(c == '-') return -nextInt();
            int res = 0;
            do{
                res *= 10;
                res += c - '0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    long nextLong(){
        try{
            int c = System.in.read();
            if(c == -1) return -1;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return -1;
            }
            if(c == '-') return -nextLong();
            long res = 0;
            do{
                res *= 10;
                res += c-'0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    double nextDouble(){
        return Double.parseDouble(next());
    }

    String next(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(Character.isWhitespace(c))
                c = System.in.read();
            do{
                res.append((char)c);
            }while(!Character.isWhitespace(c=System.in.read()));
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    String nextLine(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(c == '\r' || c == '\n')
                c = System.in.read();
            do{
                res.append((char)c);
                c = System.in.read();
            }while(c != '\r' && c != '\n');
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    public static void main(String[] args){
        new TaskB().run();
    }
}


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main4 {

    static class Main {

        public Scanner sc;
        int n, m;

        public boolean in(int x, int y) {
            return 1 <= x && x <= n && 1 <= y && y <= m;
        }

        public void run() {
            n = sc.nextInt();
            m = sc.nextInt();
            int px = sc.nextInt(), py = sc.nextInt();
            int k = sc.nextInt();
            long steps = 0;
            while (k-- > 0) {
                int dx = sc.nextInt(), dy = sc.nextInt();
                int x = px, y = py;
                while (in(x + dx, y + dy)) { x += dx; y += dy; steps++; }
                px = x; py = y;
            }
            System.out.println(steps);
        }

    }

    public static void main(String[] args) {
        Main main = new Main();
        try { main.sc = new Scanner(new FileInputStream("test.in")); }
        catch (FileNotFoundException e) { main.sc = new Scanner(System.in); }
        main.run();
    }

}


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main4 {

    static class Main {

        public Scanner sc;
        int n, m;

        public boolean in(int x, int y) {
            return 1 <= x && x <= n && 1 <= y && y <= m;
        }

        public void run() {
            n = sc.nextInt();
            m = sc.nextInt();
            int px = sc.nextInt(), py = sc.nextInt();
            int k = sc.nextInt();
            long steps = 0;
            while (k-- > 0) {
                int dx = sc.nextInt(), dy = sc.nextInt();
                int l = 0, u = Math.max(m, n);
                while (u - l > 1) {
                    int m = (l + u) / 2;
                    if (in(px + dx*m, py + dy*m)) l = m;
                    else u = m;
                }
                //System.err.println(l + " " + u);
                steps += l;
                px += dx * l; py += dy * l;
            }
            System.out.println(steps);
        }

    }

    public static void main(String[] args) {
        Main main = new Main();
        try { main.sc = new Scanner(new FileInputStream("test.in")); }
        catch (FileNotFoundException e) { main.sc = new Scanner(System.in); }
        main.run();
    }

}


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main4 {

    static class Main {

        public Scanner sc;
        int n, m;

        public boolean in(int x, int y) {
            return 1 <= x && x <= m && 1 <= y && y <= n;
        }

        public void run() {
            n = sc.nextInt();
            m = sc.nextInt();
            int px = sc.nextInt(), py = sc.nextInt();
            int k = sc.nextInt();
            long steps = 0;
            while (k-- > 0) {
                int dx = sc.nextInt(), dy = sc.nextInt();
                int x = px, y = py;
                while (in(x + dx, y + dy)) { x += dx; y += dy; steps += dx + dy; }
                px = x; py = y;
            }
            System.out.println(steps);
        }

    }

    public static void main(String[] args) {
        Main main = new Main();
        try { main.sc = new Scanner(new FileInputStream("test.in")); }
        catch (FileNotFoundException e) { main.sc = new Scanner(System.in); }
        main.run();
    }

}


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main4 {

    static class Main {

        public Scanner sc;
        long n, m;

        public boolean in(long x, long y) {
            return 1 <= x && x <= m && 1 <= y && y <= n;
        }

        public void run() {
            n = sc.nextInt();
            m = sc.nextInt();
            long px = sc.nextInt(), py = sc.nextInt();
            long k = sc.nextInt();
            long steps = 0;
            while (k-- > 0) {
                long dx = sc.nextInt(), dy = sc.nextInt();
                long x = px, y = py;
                while (in(x + dx, y + dy)) { x += dx; y += dy; steps++; }
                px = x; py = y;
            }
            System.out.println(steps);
        }

    }

    public static void main(String[] args) {
        Main main = new Main();
        try { main.sc = new Scanner(new FileInputStream("test.in")); }
        catch (FileNotFoundException e) { main.sc = new Scanner(System.in); }
        main.run();
    }

}


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main4 {

    static class Main {

        public Scanner sc;
        long n, m;

        public boolean in(long x, long y) {
            return 1 <= x && x <= n && 1 <= y && y <= m;
        }

        public void run() {
            n = sc.nextInt();
            m = sc.nextInt();
            long px = sc.nextInt(), py = sc.nextInt();
            long k = sc.nextInt();
            long steps = 0;
            while (k-- > 0) {
                long dx = sc.nextInt(), dy = sc.nextInt();
                long x = px, y = py;
                while (in(x + dx, y + dy)) { x += dx; y += dy; steps++; }
                px = x; py = y;
            }
            System.out.println(steps);
        }

    }

    public static void main(String[] args) {
        Main main = new Main();
        try { main.sc = new Scanner(new FileInputStream("test.in")); }
        catch (FileNotFoundException e) { main.sc = new Scanner(System.in); }
        main.run();
    }

}


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main4 {

    static class Main {

        public Scanner sc;
        long n, m;

        public boolean in(long x, long y) {
            return 1 <= x && x <= n && 1 <= y && y <= m;
        }

        public void run() {
            n = sc.nextInt();
            m = sc.nextInt();
            long px = sc.nextInt(), py = sc.nextInt();
            long k = sc.nextInt();
            long steps = 0;
            while (k-- > 0) {
                int dx = sc.nextInt(), dy = sc.nextInt();
                long l = 0, u = Math.max(m+1, n+1);
                while (u - l > 1) {
                    long m = (l + u) / 2;
                    if (in(px + dx*m, py + dy*m)) l = m;
                    else u = m;
                }
                //System.err.println(l + " " + u);
                steps += l;
                px += dx * l; py += dy * l;
            }
            System.out.println(steps);
        }

    }

    public static void main(String[] args) {
        Main main = new Main();
        try { main.sc = new Scanner(new FileInputStream("test.in")); }
        catch (FileNotFoundException e) { main.sc = new Scanner(System.in); }
        main.run();
    }

}


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main4 {

    static class Main {

        public Scanner sc;
        int n, m;

        public boolean in(int x, int y) {
            return 1 <= x && x <= m && 1 <= y && y <= n;
        }

        public void run() {
            n = sc.nextInt();
            m = sc.nextInt();
            int px = sc.nextInt(), py = sc.nextInt();
            int k = sc.nextInt();
            long steps = 0;
            while (k-- > 0) {
                int dx = sc.nextInt(), dy = sc.nextInt();
                int x = px, y = py;
                while (in(x + dx, y + dy)) { x += dx; y += dy; steps++; }
                px = x; py = y;
            }
            System.out.println(steps);
        }

    }

    public static void main(String[] args) {
        Main main = new Main();
        try { main.sc = new Scanner(new FileInputStream("test.in")); }
        catch (FileNotFoundException e) { main.sc = new Scanner(System.in); }
        main.run();
    }

}


import java.util.*;

public class Steps152B
{
    public static void main(String[] args)
    {
        // Set up scanner
        Scanner sc = new Scanner(System.in);
        // System.out.println("Enter n");   // x coords 1 to n
        long n = sc.nextLong();
        // System.out.println("Enter m");   // y coords 1 to m
        long m = sc.nextLong();

        // System.out.println("Enter starting x");
        long curx = sc.nextLong();
        // System.out.println("Enter starting y");
        long cury = sc.nextLong();

        // System.out.println("Enter number of vectors");
        int k = sc.nextInt();

        long answer = 0;
        for (int i=0; i<k; i++)
        {
            // System.out.println("Enter x of next vector");
            long dx = sc.nextLong();
            // System.out.println("Enter y of next vector");
            long dy = sc.nextLong();

            if (dx >= 0 && dy >= 0)
            {
                long xgap = n - curx;
                long ygap = m - cury;
                long xmoves = Long.MAX_VALUE;
                long ymoves = Long.MAX_VALUE;

                if (dx > 0)
                {
                    xmoves = xgap/dx;
                }
                if (dy > 0)
                {
                    ymoves = ygap/dy;
                }
                long moves = Math.min(xmoves, ymoves);
                answer += moves;
                curx += moves * dx;
                cury += moves * dy;
            }
            else if (dx >= 0 && dy <= 0)
            {
                long xgap = n - curx;
                long ygap = cury - 1;
                long xmoves = Long.MAX_VALUE;
                long ymoves = Long.MAX_VALUE;

                if (dx > 0)
                {
                    xmoves = xgap/dx;
                }
                if (dy < 0)
                {
                    ymoves = -ygap/dy;
                }
                long moves = Math.min(xmoves, ymoves);
                answer += moves;
                curx += moves * dx;
                cury += moves * dy;
            }
            else if (dx <= 0 && dy >= 0)
            {
                long xgap = curx - 1;
                long ygap = m - cury;
                long xmoves = Long.MAX_VALUE;
                long ymoves = Long.MAX_VALUE;

                if (dx < 0)
                {
                    xmoves = -xgap/dx;
                }
                if (dy > 0)
                {
                    ymoves = ygap/dy;
                }
                long moves = Math.min(xmoves, ymoves);
                answer += moves;
                curx += moves * dx;
                cury += moves * dy;
            }
            else     // dx and dy both negative
            {
                long xgap = curx - 1;
                long ygap = cury - 1;
                long xmoves = Long.MAX_VALUE;
                long ymoves = Long.MAX_VALUE;

                if (dx < 0)
                {
                    xmoves = -xgap/dx;
                }
                if (dy < 0)
                {
                    ymoves = -ygap/dy;
                }
                long moves = Math.min(xmoves, ymoves);
                answer += moves;
                curx += moves * dx;
                cury += moves * dy;
            }
            // System.out.println("Total number of moves is now " + answer);
            // System.out.println("Current position is " + curx + "," + cury);
        }
        System.out.println(answer);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Solution {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        StringTokenizer st = new StringTokenizer(in.readLine());
        long n = Integer.parseInt(st.nextToken());
        long m = Integer.parseInt(st.nextToken());

        st = new StringTokenizer(in.readLine());
        long x0 = Integer.parseInt(st.nextToken());
        long y0 = Integer.parseInt(st.nextToken());

        st = new StringTokenizer(in.readLine());
        long k = Integer.parseInt(st.nextToken());

        long ans = 0;

        for (int i = 0; i < k; i++) {
            long countX = 0;
            long countY = 0;
            long count = 0;

            st = new StringTokenizer(in.readLine());
            long dx = Integer.parseInt(st.nextToken());
            long dy = Integer.parseInt(st.nextToken());

            if (dx > 0)
                countX = (n - x0) / dx;
            else if (dx < 0)
                countX = (x0 - 1) / (-dx);
            else
                countX = Long.MAX_VALUE;

            if (dy > 0)
                countY = (m - y0) / dy;
            else if (dy < 0)
                countY = (y0 - 1) / (-dy);
            else
                countY = Long.MAX_VALUE;

            count = Math.min(countX, countY);

            x0 += count * dx;
            y0 += count * dy;

            ans += count;
        }

        out.println(ans);
        out.close();
    }
}


import java.util.*;
import java.math.*;
import java.io.*;

public class Main
{
    static int min(int x, int y)
    {
        return x<y?x:y;
    }
    static void Print(int x)
    {
        System.out.println(x);
    }
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int sx = in.nextInt(), sy = in.nextInt();
        int q = in.nextInt();
        long ret = 0;
        for(int u=0;u<q;++u)
        {
            int dx = in.nextInt(), dy = in.nextInt();
            int step = 0;
            if(dx == 0 && dy == 0)step = 0;
            else if(dx == 0)
            {
                if(dy > 0)step = (m - sy) / dy;
                else step = (1 - sy) / dy;
            }
            else if(dy == 0)
            {
                if(dx > 0)step = (n - sx) / dx;
                else step = (1 - sx) / dx;
            }
            else
            {
                if(dx > 0 && dy > 0)step = min((n - sx) / dx, (m - sy) / dy);
                if(dx > 0 && dy < 0)step = min((n - sx) / dx, (1 - sy) / dy);
                if(dx < 0 && dy > 0)step = min((1 - sx) / dx, (m - sy) / dy);
                if(dx < 0 && dy < 0)step = min((1 - sx) / dx, (1 - sy) / dy);
            }
            ret += step;
            //Print(step);
            sx += dx * step;
            sy += dy * step;
        }
        System.out.println(ret);
    }
}


import static java.lang.Math.*;
import static java.math.BigInteger.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import java.math.*;
import java.util.*;
import java.io.*;

public class B {
	public static void main(String[] args) {
		new B().run();
	}
	Scanner in = new Scanner(System.in);

	void run() {
		final long INF = 1001001001001001001L;
		for (; in.hasNext(); ) {
			long m = in.nextLong(), n = in.nextLong();
			long x = in.nextLong(), y = in.nextLong();
			int k = in.nextInt();
			long[] xs = new long[k], ys = new long[k];
			for (int i = 0; i < k; ++i) {
				xs[i] = in.nextLong();
				ys[i] = in.nextLong();
			}
			long ans = 0;
			for (int i = 0; i < k; ++i) {
				long tmp = INF;
				if (xs[i] < 0) {
					if (tmp > (x - 1) / -xs[i]) {
						tmp = (x - 1) / -xs[i];
					}
				} else if (xs[i] > 0) {
					if (tmp > (m - x) / xs[i]) {
						tmp = (m - x) / xs[i];
					}
				}
				if (ys[i] < 0) {
					if (tmp > (y - 1) / -ys[i]) {
						tmp = (y - 1) / -ys[i];
					}
				} else if (ys[i] > 0) {
					if (tmp > (n - y) / ys[i]) {
						tmp = (n - y) / ys[i];
					}
				}
// _out(tmp);
				x += xs[i] * tmp;
				y += ys[i] * tmp;
				ans += tmp;
			}
			System.out.println(ans);
		}
	}

	void _out(Object...os) {
		System.out.println(deepToString(os));
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class B {
    static BufferedReader reader;
    static StringTokenizer tokenizer;
    static PrintWriter writer;

    static void init() {
        reader = new BufferedReader(new InputStreamReader(System.in));

        writer = new PrintWriter(System.out);
    }

    static String nextToken() {
        while (tokenizer == null || !tokenizer.hasMoreTokens())
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                System.out.println(e);
                System.exit(1);
            }
        return tokenizer.nextToken();
    }

    static byte nextByte() {
        return Byte.parseByte(nextToken());
    }

    static short nextShort() {
        return Short.parseShort(nextToken());
    }

    static int nextInt() {
        return Integer.parseInt(nextToken());
    }

    static long nextLong() {
        return Long.parseLong(nextToken());
    }

    static float nextFloat() {
        return Float.parseFloat(nextToken());
    }

    static double nextDouble() {
        return Double.parseDouble(nextToken());
    }

    static void solve() {
        int n = nextInt(), m = nextInt(), x = nextInt(), y = nextInt(), k = nextInt(), steps = 0;
        for (int i = 0; i < k; i++) {
            int dx = nextInt(), dy = nextInt();

            int countX;
            if (dx > 0) countX = (n - x) / dx;
            else if (dx < 0) countX = (1 - x) / dx;
            else countX = Integer.MAX_VALUE;

            int countY;
            if (dy > 0) countY = (m - y) / dy;
            else if (dy < 0) countY = (1 - y) / dy;
            else countY = Integer.MAX_VALUE;

            int count = Math.min(countX, countY);

            x += dx * count;
            y += dy * count;
            steps += count;
        }

        writer.println(steps);
    }

    static void close() {
        try {
            reader.close();

            writer.flush();
            writer.close();
        } catch (IOException e) {
            System.out.println(e);
            System.exit(1);
        }
    }

    public static void main(String[] args) {
        init();
        solve();
        close();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class B {
    static BufferedReader reader;
    static StringTokenizer tokenizer;
    static PrintWriter writer;

    static void init() {
        reader = new BufferedReader(new InputStreamReader(System.in));

        writer = new PrintWriter(System.out);
    }

    static String nextToken() {
        while (tokenizer == null || !tokenizer.hasMoreTokens())
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                System.out.println(e);
                System.exit(1);
            }
        return tokenizer.nextToken();
    }

    static byte nextByte() {
        return Byte.parseByte(nextToken());
    }

    static short nextShort() {
        return Short.parseShort(nextToken());
    }

    static int nextInt() {
        return Integer.parseInt(nextToken());
    }

    static long nextLong() {
        return Long.parseLong(nextToken());
    }

    static float nextFloat() {
        return Float.parseFloat(nextToken());
    }

    static double nextDouble() {
        return Double.parseDouble(nextToken());
    }

    static void solve() {
        int n = nextInt(), m = nextInt(), x = nextInt(), y = nextInt(), k = nextInt();
        long steps = 0;
        for (int i = 0; i < k; i++) {
            int dx = nextInt(), dy = nextInt();

            int countX;
            if (dx > 0) countX = (n - x) / dx;
            else if (dx < 0) countX = (1 - x) / dx;
            else countX = Integer.MAX_VALUE;

            int countY;
            if (dy > 0) countY = (m - y) / dy;
            else if (dy < 0) countY = (1 - y) / dy;
            else countY = Integer.MAX_VALUE;

            int count = Math.min(countX, countY);

            x += dx * count;
            y += dy * count;
            steps += count;
        }

        writer.println(steps);
    }

    static void close() {
        try {
            reader.close();

            writer.flush();
            writer.close();
        } catch (IOException e) {
            System.out.println(e);
            System.exit(1);
        }
    }

    public static void main(String[] args) {
        init();
        solve();
        close();
    }
}