import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.TreeSet; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int[] x = new int[n]; int[] y = new int[n]; for (int i = 0; i < n; i++) { String[] sa = br.readLine().split(" "); x[i] = Integer.parseInt(sa[0]); y[i] = Integer.parseInt(sa[1]); } List> list = new ArrayList<>(1000); for (int i = 0; i < 1000; i++) { list.add(new TreeSet<>()); } int m = Integer.parseInt(br.readLine()); for (int i = 0; i < m; i++) { String[] sa = br.readLine().split(" "); int z = Integer.parseInt(sa[0]); int w = Integer.parseInt(sa[1]); list.get(z).add(w); } br.close(); int ans = 10000; for (int i = 0; i < n; i++) { int xi = x[i]; int yi = y[i]; int start = Math.max(xi - ans, 0); int end = Math.min(xi + ans, 999); for (int j = start; j <= end; j++) { int xj = Math.abs(xi - j); TreeSet set = list.get(j); Integer e = set.floor(yi); if (e != null) { ans = Math.min(ans, xj + yi - e); } e = set.ceiling(yi); if (e != null) { ans = Math.min(ans, xj + e - yi); } } } System.out.println(ans); } }