/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package security; import java.awt.Point; import java.util.LinkedList; import java.util.Scanner; import java.io.BufferedReader; import java.io.InputStreamReader; /** * * @author cteam087 */ public class Security { public static void main(String[] args) throws Exception { // TODO code application logic here InputStreamReader r = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(r); Scanner sc = new Scanner(br.readLine()); LinkedList al = new LinkedList<>(); LinkedList al2 = new LinkedList<>(); LinkedList al3 = new LinkedList<>(); int N, Q; N = sc.nextInt(); Q = sc.nextInt(); for (int i = 0; i < N; i++) { sc = new Scanner(br.readLine()); al.add(new Point(sc.nextInt(), sc.nextInt())); } for (int i = 0; i < Q; i++) { sc = new Scanner(br.readLine()); al2.add(new Point(sc.nextInt(), sc.nextInt())); } br.close(); r.close(); int distanceX, distanceY; for (Point incident : al2) { for (Point guard : al) { distanceX = Math.abs(incident.x - guard.x); distanceY = Math.abs(incident.y - guard.y); if(distanceX > distanceY){ al3.add(distanceX); } else al3.add(distanceY); } int min = Integer.MAX_VALUE; for (int i = 0; i < al3.size(); i++) { if (min > al3.get(i)) { min = al3.get(i); } } System.out.println(min); al3.clear(); } } }