/*******************************************************************************
网络赛水题,线扫描两下就完了,从左至右,从上至下。。。蛋疼的课设+期末考试终于结束了!
*******************************************************************************/
#include <iostream>
#include <functional>
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <utility>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <limits>
#include <memory>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;
#define LOWBIT(x) ( (x) & ( (x) ^ ( (x) - 1 ) ) )
#define CLR(x, k) memset((x), (k), sizeof(x))
#define CPY(t, s) memcpy((t), (s), sizeof(s))
#define SC(t, s) static_cast<t>(s)
#define LEN(s) static_cast<int>( strlen((s)) )
#define SZ(s) static_cast<int>( (s).size() )
typedef double LF;
typedef __int64 LL; //VC
typedef unsigned __int64 ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VF;
typedef vector<string> VS;
template <typename T>
T sqa(const T & x)
{
return x * x;
}
template <typename T>
T gcd(T a, T b)
{
if (!a || !b)
{
return max(a, b);
}
T t;
while (t = a % b)
{
a = b;
b = t;
}
return b;
};
const int INF_INT = 0x3f3f3f3f;
const LL INF_LL = 0x7fffffffffffffffLL; //15f
const double oo = 10e9;
const double eps = 10e-7;
const double PI = acos(-1.0);
#define ONLINE_JUDGE
const int MAXN = 1004;
int n, R;
int tx[MAXN];
struct Node
{
int x, y;
int id;
}nd[MAXN], tt[MAXN];
bool cmp_y(const Node & na, const Node & nb)
{
return na.y < nb.y;
}
void ace()
{
int xcnt;
int res;
while (cin >> n >> R)
{
for (int i = 0; i < n; ++i)
{
cin >> nd[i].x >> nd[i].y;
nd[i].id = i;
tx[i] = nd[i].x;
}
sort(nd, nd + n, cmp_y);
sort(tx, tx + n);
xcnt = unique_copy(tx, tx + n, tx) - tx;
res = 0;
for (int i = 0; i < xcnt; ++i)
{
int left = tx[i];
int right = left + R;
int ycnt = 0;
for (int k = 0; k < n; ++k)
{
if (left <= nd[k].x && nd[k].x <= right)
{
tt[ycnt++] = nd[k];
}
}
if (0 == ycnt)
{
continue ;
}
int low = 0, high = 0;
while (low < ycnt && high < ycnt)
{
if (tt[high].y - tt[low].y <= R)
{
res = max(res, high - low + 1);
++high;
}
else
{
++low;
}
}
}
cout << res << endl;
}
return ;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
ace();
return 0;
}