#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long n, r;
  cin >> n >> r;
  r *= 2;
  vector<vector<long long>> a((size_t)(long long)4e6 + 1);
  for (long long i = 0; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    a[x + y + (long long)2e6].push_back(x - y + (long long)2e6);
  }
  long long tree_size = 1 << 23;
  vector<long long> tree_add((size_t)tree_size, 0),
      tree_max((size_t)tree_size, 0);
  function<void(long long, long long, long long, long long, long long,
                long long)>
      tree_update = [&](long long tree_v, long long tree_l, long long tree_r,
                        long long l, long long r, long long x) {
        if (tree_l != tree_r) {
          tree_add[tree_v * 2 + 0] += tree_add[tree_v];
          tree_add[tree_v * 2 + 1] += tree_add[tree_v];
        } else {
          tree_max[tree_v] += tree_add[tree_v];
        }
        tree_add[tree_v] = 0;
        if (tree_l >= l && tree_r <= r) {
          tree_add[tree_v] += x;
        } else if (tree_l <= r && tree_r >= l) {
          tree_update(tree_v * 2 + 0, tree_l, tree_l + (tree_r - tree_l) / 2, l,
                      r, x);
          tree_update(tree_v * 2 + 1, tree_r - (tree_r - tree_l) / 2, tree_r, l,
                      r, x);
        }
        if (tree_l != tree_r) {
          tree_max[tree_v] =
              max(tree_max[tree_v * 2 + 0] + tree_add[tree_v * 2 + 0],
                  tree_max[tree_v * 2 + 1] + tree_add[tree_v * 2 + 1]);
        }
      };
  long long m = -1;
  for (long long i = 0; i <= (long long)4e6; i++) {
    if (i - r - 1 >= 0) {
      for (long long j : a[i - r - 1]) {
        tree_update(1, 0, tree_size / 2 - 1, j, min(j + r, (long long)4e6), -1);
      }
    }
    for (long long j : a[i]) {
      tree_update(1, 0, tree_size / 2 - 1, j, min(j + r, (long long)4e6), 1);
    }
    m = max(m, tree_max[1] + tree_add[1]);
  }
  cout << m << endl;
  return 0;
}
