import sys from collections import deque import heapq def main(): N, K = map(int, sys.stdin.readline().split()) sx, sy, gx, gy = map(int, sys.stdin.readline().split()) landmarks = [] existing = set() existing.add((sx, sy)) existing.add((gx, gy)) for _ in range(N): x, y = map(int, sys.stdin.readline().split()) landmarks.append((x, y)) existing.add((x, y)) nodes = [(sx, sy), (gx, gy)] + landmarks M = len(nodes) # Precompute d_matrix d_matrix = [[0] * M for _ in range(M)] for i in range(M): for j in range(i+1, M): dx = abs(nodes[i][0] - nodes[j][0]) dy = abs(nodes[i][1] - nodes[j][1]) d = dx + dy d_matrix[i][j] = d d_matrix[j][i] = d # Initial binary search bounds initial_high = d_matrix[0][1] low = 1 high = initial_high answer = initial_high while low <= high: mid = (low + high) // 2 # BFS step to check connectivity with existing nodes and edges <= mid visited = [False]*M q = deque() q.append(0) visited[0] = True found = False while q: u = q.popleft() if u == 1: found = True break for v in range(M): if u != v and not visited[v] and d_matrix[u][v] <= mid: visited[v] = True q.append(v) if found: answer = mid high = mid -1 continue # Dijkstra's algorithm heap = [] dist = [float('inf')] * M dist[0] = 0 heapq.heappush(heap, (0, 0)) while heap: current_cost, u = heapq.heappop(heap) if u == 1: break if current_cost > dist[u]: continue for v in range(M): if u == v: continue d = d_matrix[u][v] if d ==0: continue # shouldn't happen required = (d + mid -1) // mid -1 if d <= mid: required = 0 if dist[v] > dist[u] + required: dist[v] = dist[u] + required heapq.heappush(heap, (dist[v], v)) if dist[1] <= K: answer = mid high = mid -1 else: low = mid +1 print(answer) if __name__ == "__main__": main()