Problem: Niwango-kun, an employee of Dwango Co., Ltd., likes Niconico TV-chan, so he collected a lot of soft toys of her and spread them on the floor.

Niwango-kun has N black rare soft toys of Niconico TV-chan and they are spread together with ordinary ones. He wanted these black rare soft toys to be close together, so he decided to rearrange them.

In an infinitely large two-dimensional plane, every lattice point has a soft toy on it. The coordinates (x_i,y_i) of N black rare soft toys are given. All soft toys are considered to be points (without a length, area, or volume).

He may perform the following operation arbitrarily many times:

* Put an axis-aligned square with side length D, rotate the square by 90 degrees with four soft toys on the four corners of the square. More specifically, if the left bottom corner's coordinate is (x, y), rotate four points (x,y) \rightarrow (x+D,y) \rightarrow (x+D,y+D) \rightarrow (x,y+D) \rightarrow (x,y) in this order. Each of the four corners of the square must be on a lattice point.



Let's define the scatteredness of an arrangement by the minimum side length of an axis-aligned square enclosing all black rare soft toys. Black rare soft toys on the edges or the vertices of a square are considered to be enclosed by the square.

Find the minimum scatteredness after he performs arbitrarily many operations.

Constraints

* 2 \leq N \leq 10^5
* 1 \leq D \leq 1000
* 0 \leq x_i, y_i \leq 10^9
* Given coordinates are pairwise distinct
* All numbers given in input are integers

Input

Input is given from Standard Input in the following format:


N D
x_1 y_1
:
x_N y_N


Output

Print the answer.

Examples

Input

3 1
0 0
1 0
2 0


Output

1


Input

19 2
1 3
2 3
0 1
1 1
2 1
3 1
4 4
5 4
6 4
7 4
8 4
8 3
8 2
8 1
8 0
7 0
6 0
5 0
4 0


Output

4


Input

8 3
0 0
0 3
3 0
3 3
2 2
2 5
5 2
5 5


Output

4

Solution (in CPP):

Solution:
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<int,pint> tint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
lint num[1050][1050];
int dat[3][2010][2010];
int d;
lint num2(int id,int lx,int ly,int hx,int hy){
	if(hx<0 || hy<0) return 0;
	int ret=dat[id][hx][hy];
	if(lx>0) ret-=dat[id][lx-1][hy];
	if(ly>0) ret-=dat[id][hx][ly-1];
	if(lx>0 && ly>0) ret+=dat[id][lx-1][ly-1];
	return ret;
}
bool cal(int mi){
	mi++;
	lint a=mi/d,b=mi%d;
	memset(dat,0,sizeof(dat));
	rep(i,d) rep(j,d) rep(k,2) rep(l,2){
		if(num[i][j]<=a*a) dat[0][i+k*d][j+l*d]++;
		if(num[i][j]<=a*(a+1)) dat[1][i+k*d][j+l*d]++;
		if(num[i][j]<=(a+1)*(a+1)) dat[2][i+k*d][j+l*d]++;
	}
	rep(i,d*2) rep(j,d*2) rep(k,3){
		if(i>0) dat[k][i][j]+=dat[k][i-1][j];
		if(j>0) dat[k][i][j]+=dat[k][i][j-1];
		if(i>0 && j>0) dat[k][i][j]-=dat[k][i-1][j-1];
	}
	rep(i,d) rep(j,d){
		if(num2(2,i,j,i+b-1,j+b-1)>=b*b && num2(1,i,j+b,i+b-1,j+d-1)>=b*(d-b) && num2(1,i+b,j,i+d-1,j+b-1)>=b*(d-b) && num2(0,i+b,j+b,i+d-1,j+d-1)>=(d-b)*(d-b)){
			return true;
		}
	}
	return false;
}
int main()
{
	memset(num,0,sizeof(num));
	int n,x,y;
	cin>>n>>d;
	/*if(d>30){
		cout<<0<<endl;return 0;
	}*/
	rep(i,n){
		cin>>x>>y;num[x%d][y%d]++;
	}
	int lo=0,hi=1001001001;
	//cal(0);
	while(hi>lo){
		lint mi=(hi+lo)/2;
		if(cal(mi)) hi=mi;else lo=mi+1;
	}
	cout<<lo<<endl;
}