#include <bits/stdc++.h>
using namespace std;

int main()
{
    int N, Q, di, pi, n, ki;
    cin>>N>>Q;
    int br=0;
    int br1=0;
    int br3=0;
    int d=1;
    int p=0;
    string nn="";
    string rr="";
    string k;
    while(br<N){//
    cin>>di>>pi;
    while(d<di){
    if(p>0) n=1;
    else n=0;
    if (n!=0)p=p-1;
    nn=nn+to_string(n);//cout<<n;
    d++;}
    p=p+pi;
    br=br+1;}//cin N
    int m=di+p;
    while(d<m){
    if(p>0) n=1;
    else n=0;
    if (n!=0)p=p-1;
    nn=nn+to_string(n);//cout<<n;
    d++;}
    //cout<<nn;
    int x=0;
    string rs="a";
    int r=0;
    while(br1<Q){//
    cin>>ki;
    r=0;
    k.clear();
    br3=0;
    x=0;
    while (br3<ki){
        k=nn.substr(x,1);
        x=x+1;
        r=r+stoi(k);
    br3=br3+1;}
    rr=rr+to_string(r)+rs;
    br1=br1+1;}//cin q*/
    
    
    int br4=0;
    while(br4<Q){//cout<<rr;
    string g=rr.substr(0,rr.find("a"));
    rr.erase(0,rr.find("a")+1);
    cout<<g<<"\n";
    br4=br4+1;
    }
    
    

    return 0;
}