#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
struct point
{
int x,y;
}a[1005];
bool cmp(point a,point b)
{
return a.x<b.x;
}
int main()
{
int n;
int m;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=0;i<n;i++)
{
scanf("%d%d",&a[i].x,&a[i].y);
}
sort(a,a+n,cmp);
int mymin=-1;
queue<point>q;
int temp;
for(int i=0;i<n;i++)
{
while(!q.empty())
{
q.pop();
}
for(int j=0;j<n;j++)
{
if(a[j].y>=a[i].y && a[j].y<=a[i].y+m)
{
while(!q.empty() && a[j].x>q.front().x+m)
{
q.pop();
}
q.push(a[j]);
temp=q.size();
if(temp>mymin)
mymin=temp;
}
}
temp=0;
}
printf("%d\n",mymin);
}
return 0;
}
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
struct point
{
int x,y;
}a[1005];
bool cmp(point a,point b)
{
return a.x<b.x;
}
int main()
{
int n;
int m;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=0;i<n;i++)
{
scanf("%d%d",&a[i].x,&a[i].y);
}
sort(a,a+n,cmp);
int mymin=-1;
queue<point>q;
int temp;
for(int i=0;i<n;i++)
{
while(!q.empty())
{
q.pop();
}
for(int j=0;j<n;j++)
{
if(a[j].y>=a[i].y && a[j].y<=a[i].y+m)
{
while(!q.empty() && a[j].x>q.front().x+m)
{
q.pop();
}
q.push(a[j]);
temp=q.size();
if(temp>mymin)
mymin=temp;
}
}
temp=0;
}
printf("%d\n",mymin);
}
return 0;
}