#include <bits/stdc++.h>
#define x first
#define y second
using PII = std::pair<int, int>;
const int N = 100010;
int n, m, ans = 1e9;
PII a[N];
std::priority_queue<PII> f, g;
int main() {
freopen("double_muscle.in", "r", stdin);
freopen("double_muscle.out", "w", stdout);
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);
for (int i = 1; i <= n; ++ i) {
while (f.size() && f.top().x - a[i].y >= m)
ans = std::min(ans, a[i].x - f.top().y), f.pop();
while (g.size() && g.top().x + a[i].y >= m)
ans = std::min(ans, a[i].x - g.top().y), g.pop();
f.push({ a[i].y, a[i].x });
g.push({ -a[i].y, a[i].x });
}
std::cout << ans << '\n';
return 0;
}