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<bits/stdc++.h>
#define debug(x) cerr<<#x<<" = "<<x
#define sp <<"  "
#define el <<endl
#define LL long long
#define M 100020
using namespace std;
namespace IO{
	const int BS=(1<<20)+5; int Top=0;
	char Buffer[BS],OT[BS],*OS=OT,*HD,*TL,SS[20]; const char *fin=OT+BS-1;
	char Getchar(){if(HD==TL){TL=(HD=Buffer)+fread(Buffer,1,BS,stdin);} return (HD==TL)?EOF:*HD++;}
	void flush(){fwrite(OT,1,OS-OT,stdout);}
	void Putchar(char c){*OS++ =c;if(OS==fin)flush(),OS=OT;}
	void write(int x){
		if(!x){Putchar('0');return;} if(x<0) x=-x,Putchar('-');
		while(x) SS[++Top]=x%10,x/=10;
		while(Top) Putchar(SS[Top]+'0'),--Top;
	}
	int read(){
		int nm=0,fh=1; char cw=getchar();
		for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
		for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
		return nm*fh;
	}
}
using namespace IO;
#define bas 1005
int n,m,p[1020][1020],X[M],Y[M],D,ans,c[2020][2020],len[M][2];
void calc(int id,int x){
	int k=sqrt(x);while(k*k<x) k++;
	len[id][0]=k,len[id][1]=(x/k)+(x%k>0);
	len[id][0]*=D,len[id][0]-=D;
	len[id][1]*=D,len[id][1]-=D;
	if(len[id][0]>len[id][1]) swap(len[id][0],len[id][1]);
}
void add(int dt,int x,int y,int xx,int yy){
	c[x][y]+=dt,c[x][yy+1]-=dt,c[xx+1][y]-=dt,c[xx+1][yy+1]+=dt;
}
void mdf(int kd,int x,int y,int t1,int t2,int dis){
	int q1=dis-t1,q2=dis-t2; if(q1<0||q2<0) return;
	if(q1>=D) q1=D-1; if(q2>=D) q2=D-1;
	add(kd,x-q1+bas,y-q2+bas,x+bas,y+bas);	
}
int tot(int x,int y){return c[x+bas][y+bas]+c[x-D+bas][y+bas]+c[x+bas][y-D+bas]+c[x-D+bas][y-D+bas];}
bool solve(int dis){
	memset(c,0,sizeof(c));
	for(int i=1;i<=n;i++){
		int x=X[i],y=Y[i];
		mdf(1,x,y,len[i][0],len[i][1],dis);
		mdf(1,x,y,len[i][1],len[i][0],dis);
		mdf(-1,x,y,len[i][1],len[i][1],dis);
	}
	for(int i=bas-D;i<=bas+D;i++){
		for(int j=bas-D;j<=bas+D;j++) c[i][j]=c[i][j]+c[i-1][j]+c[i][j-1]-c[i-1][j-1];
	}
	for(int i=0;i<D;i++){
		for(int j=0;j<D;j++) if(tot(i,j)==n){return true;}
	} return false;
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read(),D=read();
	for(int i=1;i<=n;i++){
		X[i]=read(),Y[i]=read();
		X[i]%=D,Y[i]%=D,p[X[i]][Y[i]]++;
	}
	if(n==1){puts("0");return 0;} n=0;
	for(int i=0;i<D;i++){
		for(int j=0;j<D;j++){
			if(!p[i][j]) continue;
			n++,X[n]=i,Y[n]=j,calc(n,p[i][j]);
		}
	}
	for(int l=1,r=2000000002,mid=1000000001;l<=r;mid=((l+r)>>1)){
		if(solve(mid)) ans=mid,r=mid-1;else l=mid+1;
	}printf("%d\n",ans);
	return 0;
}