#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+5,inf=1e18;
int n,d,head[5],tail[5],q[5][N];
struct node{int x,y;}p[N];
int cmp(node x,node y){return x.x<y.x;}
int work(int i,int x,int op){
for(;head[op]<=tail[op]&&(op==1?p[q[op][tail[op]]].y<=p[i].y:p[q[op][tail[op]]].y>=p[i].y);)tail[op]--;
q[op][++tail[op]]=p[i].x;
for(;head[op]<=tail[op]&&q[op][tail[op]]-q[op][head[op]]>x;)head[op]++;
return p[q[op][head[op]]].y;
}
bool check(int x){
head[1]=head[2]=1,tail[1]=tail[2]=0;
for(int i=1;i<=n;i++)
if(work(i,x,1)-work(i,x,2)>=d)return 1;
return 0;
}
signed main(){
cin>>n>>d;
for(int i=1;i<=n;i++)cin>>p[i].x>>p[i].y;
sort(p+1,p+n+1,cmp);
int l=0,r=inf+1;
for(;l+1<r;){
int mid=l+r>>1;
if(check(mid))r=mid;
else l=mid;
}
cout<<(r!=inf+1?r:-1);
return 0;
}