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>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

const pid_t pid = getpid();
// Problem Specific Parameter:

inline ll mul(ll a, ll b){
	if(a == 0 or b == 0) return 0LL;
	const ll limit = 1LL << 20;
	if(a > limit or b > limit) return limit;
	return min<ll>(limit, a * b);
}

int ary[2010][2010];
int csum[3][2010][2010];

bool query(int k,int a,int b,int c,int d){
	int total = (b - a) * (d - c);
	total -= csum[k][a][c];
	total += csum[k][b][c];
	total += csum[k][a][d];
	total -= csum[k][b][d];
	return (total == 0);
}

bool check(ll len,ll d){
	vector<ll> limit;
	limit.push_back(mul(len / d + 1LL, len / d + 1LL));
	limit.push_back(mul(len / d + 0LL, len / d + 1LL));
	limit.push_back(mul(len / d + 0LL, len / d + 0LL));

	rep(k,3){
		rep(i,2 * d)rep(j, 2 * d){
			csum[k][i][j] = (ary[i][j] <= limit[k]);
		}

		rrep(i, 2 * d)rrep(j, 2 * d){
			csum[k][i][j] += csum[k][i+1][j];
			csum[k][i][j] += csum[k][i][j+1];
			csum[k][i][j] -= csum[k][i+1][j+1];
		}
	}

	// (len / d) + (pos <= len % d)
	rep(i,d)rep(j,d){
		const int im = i + len % d + 1;
		const int ie = i + d;
		const int jm = j + len % d + 1;
		const int je = j + d;
		bool ok = true;
			
		if(query(0,i,im,j,jm) == false) ok = false;
		if(query(1,im,ie,j,jm) == false) ok = false;
		if(query(1,i,im,jm,je) == false) ok = false;
		if(query(2,im,ie,jm,je) == false) ok = false;
		if(ok) return true;
	}

	return false;
}
 
int main(void){
	int n,d;
	cin >> n >> d;
	
	vector<int> x(n),y(n);
	rep(i,n){
		cin >> x[i] >> y[i];
		ary[x[i] % d][y[i] % d]++;
	}
 
	rep(i,2*d)rep(j,2*d){
		if(i < d and j < d) continue;
		ary[i][j] = ary[i % d][j % d]; 
	}
 
	ll low = 0LL, high = 1LL << 40;
	while(high - low > 1){
		const ll mid = (low + high) / 2LL;
		if(check(mid,d))
			high = mid;
		else
			low = mid;
	}
 
	cout << high << endl;
	return 0;
}