// Arup Guha
// 1/8/2016
// Solution to USACO 2016 December Gold Problem: Checklist

import java.util.*;
import java.io.*;

public class checklist {

	public static int aList;
	public static int[] start;
	public static int[] end;
	public static int[][] aPts;
	public static int bList;
	public static int[][] bPts;

	public static void main(String[] args) throws Exception {

		// Read in the first list.
		Scanner stdin = new Scanner(new File("checklist.in"));
		aList = stdin.nextInt();
		bList = stdin.nextInt();
		aPts = new int[aList][2];
		for (int i=0; i<aPts.length; i++)
			for (int j=0; j<2; j++)
				aPts[i][j] = stdin.nextInt();

		// Read in the second list.
		bPts = new int[bList][2];
		for (int i=0; i<bList; i++)
			for (int j=0; j<2; j++)
				bPts[i][j] = stdin.nextInt();

		// Initialize DP array. dp[i][j][0] is min cost for getting to a[i], b[j], ending at a[i].
		//                      dp[i][j][1] is min cost for getting to a[i], b[j], ending at b[j].
		int[][][] dp = new int[aList+1][bList+1][2];
		for (int i=0; i<=aList; i++)
			for (int j=0; j<=bList; j++)
				Arrays.fill(dp[i][j], 2000000000);

		// We always start at pt 0 on the first list.
		dp[0][0][0] = 0;
		dp[1][0][0] = 0;

		for (int i=1; i<=aList; i++) {
			for (int j=0; j<=bList; j++) {

				if (i == 1 && j == 0) continue;

				// To get to state i,j,0 we must come from i-1,j,0 (move a[i-1] to a[i]) or i-1,j,1 (move b[j] to a[i]).
				if (i>1)        dp[i][j][0] = Math.min(dp[i][j][0], dp[i-1][j][0] + distsq(aPts[i-2], aPts[i-1]));
				if (i>0 && j>0) dp[i][j][0] = Math.min(dp[i][j][0], dp[i-1][j][1] + distsq(bPts[j-1], aPts[i-1]));

				// Symmetric cases to those written above, just ending at a Guernsey cow.
				if (j>1)        dp[i][j][1] = Math.min(dp[i][j][1], dp[i][j-1][1] + distsq(bPts[j-2], bPts[j-1]));
				if (j>0 && i>0) dp[i][j][1] = Math.min(dp[i][j][1], dp[i][j-1][0] + distsq(aPts[i-1], bPts[j-1]));
			}
		}

		// Write out the result, the lower of the two possible ending states.
		PrintWriter out = new PrintWriter(new FileWriter("checklist.out"));
		if (aList > 1)
			out.println(dp[aList][bList][0]);
		else
			out.println(annoyingCase());
		out.close();
		stdin.close();
	}

	public static int annoyingCase() {

		// Must go a to b in this case at first.
		int res = distsq(aPts[0], bPts[0]);

		// Then do the rest of b.
		for (int i=1; i<bList; i++)
			res += distsq(bPts[i-1], bPts[i]);

		// And return to the start point of a... (how annoying!)
		res += distsq(bPts[bList-1], aPts[0]);
		return res;
	}

	public static int distsq(int[] a, int[] b) {
		return (a[0]-b[0])*(a[0]-b[0]) + (a[1]-b[1])*(a[1]-b[1]);
	}
}