#include <fstream>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
ifstream F("poligon.in");
ofstream G("poligon.out");
#define x first
#define y second
#define st second.first
#define dr second.second
#define mid first
typedef pair<double,double> Pair;
typedef pair< Pair,pair<Pair,Pair> > Banda;
const int Nmax = 810;
const int Mmax = 60010;
const int Pars = 1000010;
int N,M,Co,Sol,Act;
Pair Poly[Nmax];
int Point[Nmax];
char Str[Pars];
#define make_band(A,B,C) ( make_pair(C,make_pair(A,B)) )
vector <Banda> Band[Nmax];
inline Pair Mid(Pair A,Pair B)
{
return make_pair( (A.x+B.x)/2 , (A.y+B.y)/2 );
}
inline Pair Int(Pair A,Pair B,Pair D)
{
return make_pair(D.x, B.y + (B.y - A.y) * (D.x - B.x) / (B.x - A.x));
}
int Find_band(Pair P,int Left,int Right)
{
if ( Left==Right ) return Left;
int Middle = ( Left+Right ) / 2;
if ( P.x < Point[Middle] )
return Find_band(P,Left,Middle-1);
if ( P.x > Point[Middle+1] )
return Find_band(P,Middle+1,Right);
return Middle;
}
#define EPS 0.000001
int Ec(Pair P,Pair A,Pair B)
{
double a = A.y - B.y ;
double b = B.x - A.x ;
double c = - A.y * B.x + B.y * A.x ;
if ( P.x*a+P.y*b+c <= EPS && P.x*a+P.y*b+c >= -EPS ) return 0;
if ( P.x*a+P.y*b+c > 0 ) return 1;
return -1;
}
int Find_line(Pair P,int Pl,int Left,int Right)
{
if ( Right-Left<2 )
{
if ( Left==Right ) return Left;
int Ecu=Ec(P,Band[Pl][Right].st,Band[Pl][Right].dr);
if ( Ecu==0 ) return 0;
if ( Ecu==1 ) return Right;
return Left;
}
int Middle=(Left+Right)/2;
int Ecu=Ec(P,Band[Pl][Middle].st,Band[Pl][Middle].dr);
if ( Ecu==-1 ) return Find_line(P,Pl,Left,Middle-1);
if ( Ecu==1 ) return Find_line(P,Pl,Middle,Right);
return 0;
}
void Get( int& A )
{ A=0;
while ( Str[Act]>'9' || Str[Act]<'0' ) ++Act;
while ( Str[Act]>='0' && Str[Act]<='9' ) A=A*10+Str[Act++]-'0';
}
int main( void )
{
F.getline(Str,Pars,EOF);
Get(N);Get(M);
for (int i=1;i<=N;++i)
{
int Cx,Cy;
Get(Cx),Get(Cy);
Poly[i]=make_pair(double(Cx),double(Cy));
Point[i]=int(Cx);
}
Poly[N+1]=Poly[1];
sort(Point+1,Point+N+1);
Co=1;
for (int i=2;i<=N;++i)
{
if ( Point[i]==Point[i-1] ) continue;
Point[++Co]=Point[i];
}
for (int i=Co+1;i<=N;++i) Point[i]=0;
for (int i=1;i<Co;++i)
{
register Pair A,B,C,D;
for (int j=1;j<=N;++j)
{
C = Poly[j];
D = Poly[j+1];
if ( C > D ) swap(C,D);
A = Int(C,D, make_pair(Point[i],0) );
B = Int(C,D, make_pair(Point[i+1],0) );
if ( A > B ) swap(A,B);
if ( (A.x > C.x && A.x < D.x) || (B.x > C.x && B.x < D.x) || A.x == C.x || B.x == D.x )
Band[i].push_back( make_band( A,B,Mid(A,B) ) );
}
sort(Band[i].begin(),Band[i].end());
}
while ( M-- )
{
int X,Y;
Get(X);Get(Y);
Pair P=make_pair(double(X),double(Y));
if ( P.x < Point[1] || P.x > Point[Co] ) continue;
int Pl = Find_band( P , 1 , Co-1 );
int Val = Ec(P, Band[Pl][0].st, Band[Pl][0].dr );
if ( Val==0 || Val==-1 )
{
if ( Val==0 ) ++Co;
continue;
}
int Nbr = Find_line( P , Pl , 0 , int(Band[Pl].size())-1 );
Sol+=1-(Nbr%2);
}
G<<Sol<<'\n';
}