// Arup Guha
// 12/17/2019
// Solution to 2014 March USACO Silver Problem: Watering the Fields

import java.util.*;
import java.io.*;

public class irrigation {
	
	public static void main(String[] args) throws Exception {
		
		// Get basic parameters.
		BufferedReader stdin = new BufferedReader(new FileReader("irrigation.in"));
		StringTokenizer tok = new StringTokenizer(stdin.readLine());
		int n = Integer.parseInt(tok.nextToken());
		int minE = Integer.parseInt(tok.nextToken());
		
		// Read in the points.
		int[][] pts = new int[n][2];
		for (int i=0; i<n; i++) {
			tok = new StringTokenizer(stdin.readLine());
			pts[i][0] = Integer.parseInt(tok.nextToken());
			pts[i][1] = Integer.parseInt(tok.nextToken());
		}
		
		// Empty graph.
		ArrayList[] g = new ArrayList[n];
		for (int i=0; i<n; i++) g[i] = new ArrayList<edge>();
		
		// Add the edges they say to add.
		for (int i=0; i<n; i++) {
			for (int j=i+1; j<n; j++) {
				int dsqr = distsqr(pts[i],pts[j]);
				if (dsqr >= minE) {
					g[i].add(new edge(i,j,dsqr));
					g[j].add(new edge(j,i,dsqr));
				}
			}
		}
		
		/*** lol - I got a TLE when I started Prim's from vertex 0. So, I resubmitted
		     by starting at a random vertex and got it accepted =)
		***/
		Random r = new Random();
		
		// Solve and output to file.
		PrintWriter out = new PrintWriter(new FileWriter("irrigation.out"));
		out.println(prims(g, r.nextInt(n)));
		out.close();		
		stdin.close();
	}
	
	// Returns the distance squared between pts p1 and p2.
	public static int distsqr(int[] p1, int[] p2) {
		return (p1[0]-p2[0])*(p1[0]-p2[0]) + (p1[1]-p2[1])*(p1[1]-p2[1]);
	}
	
	public static int prims(ArrayList<edge>[] g, int v) {
		
		// Set up Prim's.
		int n = g.length;
		boolean[] used = new boolean[n];
		used[v] = true;
		PriorityQueue<edge> pq = new PriorityQueue<edge>();
		for (edge e: g[v]) pq.offer(e);
		int numE = 0, res = 0;
		
		// Main loop.
		while (pq.size() > 0 && numE < n-1) {
			
			// Get next edge.
			edge cur = pq.poll();
			
			// Both connected, ignore.
			if (used[cur.u] && used[cur.v]) continue;
			
			// New vertex we're connecting to.
			int newv = used[cur.u] ? cur.v : cur.u;
			
			// All of our bookkeeping.
			used[newv] = true;
			res += cur.w;
			for (edge e: g[newv]) pq.offer(e);
			numE++;
		}
		
		// Either return mst or -1 if there is none.
		return numE == n-1 ? res : -1;
	}
}

class edge implements Comparable<edge> {
	
	public int u;
	public int v;
	public int w;
	
	public edge(int myu, int myv, int myw) {
		u = myu;
		v = myv;
		w = myw;
	}
	
	public int compareTo(edge other) {
		return w - other.w;
	}
}