#include <bits/stdc++.h>
#define x first
#define y second
using PII = std::pair<int, int>;
const int N = 100010;
int ans = 1e9;
PII a[N];
int main() {
freopen("double_muscle.in", "r", stdin);
freopen("double_muscle.out", "w", stdout);
int n, m;
std::cin >> n >> m;
for (int i = 1; i <= n; ++ i)
std::cin >> a[i].x >> a[i].y;
std::sort(a + 1, a + 1 + n, [](PII a, PII b) {
return a.y < b.y;
});
for (int i = 1; i <= n; ++ i)
for (int j = i + 1; j <= n; ++ j)
if (a[j].y - a[i].y >= m)
ans = std::min(ans, std::abs(a[i].x - a[j].x));
std::cout << ans << '\n';
return 0;
}