int fa[maxn]; voidinit_fa(int n){ for (int i = 1; i <= n; ++i) fa[i] = i; }
intfind(int x){ return x == fa[x] ? x : fa[x] = find(fa[x]); }
intmain(){ cin >> n >> m; s = n + 1; t = n + 2; for (int o = 1; o <= n; ++o) { cin >> a[o].x >> a[o].y; add_edge(s, o, a[o].y); add_edge(o, t, m - a[o].y); for (int i = 1; i < o; ++i) add_edge(o, i, dis(a[o], a[i])); sort(e + 1, e + c1 + 1); init_fa(n + 2); int s = 0; db ans = 0; for (int i = 1; i <= c1; ++i) { int u = e[i].fr, v = e[i].to, fu, fv; db w = e[i].w; if ((fu = find(u)) == (fv = find(v))) continue ; fa[fu] = fv; if (find(s) == find(t) && !ans) ans = w; if (++s == o + 1) { c1 = i; break; } } cout << (int) (ans / 2) << endl; } return0; }