#include #include using namespace std; vector> pole; int detector(int x, int y) { int step = 0; if(pole[x][y]) return 0; while(true) { for(int xs = x - step; xs <= x + step; xs++) { if (xs>=0 && xs<= 5000 &&y-step <= 5000 && y-step >=0) { if(pole[xs][y-step]) return step; if(pole[xs][y+step]) return step; } } for(int ys = y-step; ys <= y+step; ys++) { if (ys >= 0&&ys<=5000&&x-step<=5000&&x-step>=0) { if(pole[x-step][ys]) return step; if(pole[x+step][ys]) return step; } } step++; } } int main() { int grd, inc; scanf("%d %d", &grd, &inc); for(int i = 0;i<=5000;i++) { pole.push_back(vector (5001, false)); } int x, y; for (int i = 0 ; i < grd ; i++) { scanf("%d %d", &x, &y); pole[x][y] = true; } for (int i = 0 ; i < inc ; i++) { scanf("%d %d", &x, &y); printf("%d\n", detector(x,y)); } return 0; }