#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

struct Node {
    int val;
    int p[101] = {};
};

int a[200000];
Node t[800000];
int n;

void build(int x = 0, int L = 0, int R = n - 1) {
    if (L == R) {
        t[x].val = a[L];
        return;
    }
    int m = (L + R) / 2;
    build(2 * x + 1, L, m);
    build(2 * x + 2, m + 1, R);
}

void push(int x, int L, int R) {
    if (L == R) {
        if (t[x].p[t[x].val]) {
            t[x].val = t[x].p[t[x].val];
            t[x].p[t[x].val] = 0;
        }
        return;
    }
    int l = 2 * x + 1, r = 2 * x + 2;
    for (int i = 1; i <= 100; ++i) {
        t[l][i] = t[x].p[ t[l].p[i] ];
        t[r][i] = t[x].p[ t[r].p[i] ];
    }
    for (int i = 1; i <= 100; ++i) {
        t[x][i] = 0;
    }
}

void op(int l, int r, int val, int ch, int x = 0, int L = 0, int R = n - 1) {
    if (l > r)
        return;
    push(x, L, R);
    if (l == L && r == R) {
        t[x].p[val] = ch;
        return;
    }
    int m = (L + R) / 2;
    op(l, min(m, r), val, ch, 2 * x + 1, L, m);
    op(max(l, m + 1), r, val, ch, 2 * x + 2, m + 1, R);
}

int find(int i, int x = 0, int L = 0, int R = n - 1) {
    push(x, L, R);
    if (L == R) {
        return t[x].val;
    }
    int m = (L + R) / 2;
    if (i <= m) {
        return find(i, 2 * x + 1, L, m);
    } else {
        return find(i, 2 * x + 2, m + 1, R);
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    build();
    int q;
    cin >> q;
    int l, r, x, y;
    for (int i = 0; i < q; ++i) {
        cin >> l >> r >> x >> y;
        --l;
        --r;
        op(l, r, x, y);
    }
    for (int i = 0; i < n; ++i) {
        cout << find(i) << " ";
    }
    cout << endl;
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
template <typename T> ostream &operator<<(ostream &cout, vector<T> &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << " "; return cout;}
template <typename T> ostream &operator<<(ostream &cout, vector<vector<T> > &a){for(size_t i = 0; i < a.size(); ++i) cout << a[i] << endl; return cout;}
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif

struct Node {
    int val;
    int p[101] = {};
};

int a[200000];
Node t[800000];
int n;

void build(int x = 0, int L = 0, int R = n - 1) {
    if (L == R) {
        t[x].val = a[L];
        return;
    }
    int m = (L + R) / 2;
    build(2 * x + 1, L, m);
    build(2 * x + 2, m + 1, R);
}

void push(int x, int L, int R) {
    if (L == R) {
        if (t[x].p[t[x].val]) {
            t[x].val = t[x].p[t[x].val];
            t[x].p[t[x].val] = 0;
        }
        return;
    }
    int l = 2 * x + 1, r = 2 * x + 2;
    for (int i = 1; i <= 100; ++i) {
        if (t[x].p[i]) {
            for (int j = 1; j <= 100; ++j) {
                if (t[l].p[j] == i) {
                    t[l].p[j] = t[x].p[i];
                }
                if (t[r].p[j] == i) {
                    t[r].p[j] = t[x].p[i];
                }
            }
            if (t[l].p[i] == i || t[l].p[i] == 0) {
                t[l].p[i] = t[x].p[i];
            }
            if (t[r].p[i] == i || t[r].p[i] == 0) {
                t[r].p[i] = t[x].p[i];
            }
            t[x].p[i] = 0;
        }
    }
}

void op(int l, int r, int val, int ch, int x = 0, int L = 0, int R = n - 1) {
    if (l > r)
        return;
    push(x, L, R);
    if (l == L && r == R) {
        t[x].p[val] = ch;
        return;
    }
    int m = (L + R) / 2;
    op(l, min(m, r), val, ch, 2 * x + 1, L, m);
    op(max(l, m + 1), r, val, ch, 2 * x + 2, m + 1, R);
}

int find(int i, int x = 0, int L = 0, int R = n - 1) {
    push(x, L, R);
    if (L == R) {
        return t[x].val;
    }
    int m = (L + R) / 2;
    if (i <= m) {
        return find(i, 2 * x + 1, L, m);
    } else {
        return find(i, 2 * x + 2, m + 1, R);
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    build();
    int q;
    cin >> q;
    int l, r, x, y;
    for (int i = 0; i < q; ++i) {
        cin >> l >> r >> x >> y;
        --l;
        --r;
        op(l, r, x, y);
    }
    for (int i = 0; i < n; ++i) {
        cout << find(i) << " ";
    }
    cout << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int BLOCK=800;
int n,q,a[200007],pset[107][(200007/BLOCK)+100],st[100007],fs[100007];
int l,r,x,y;
int fset(int x,int num){
	if(pset[x][num]<0) return x;
	else return pset[x][num]=fset(pset[x][num],num);
}
int main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int nblock=n/BLOCK;
	if(n%BLOCK) nblock++;
	int cur=1;
	for(int i=1;i<=nblock;i++){
		st[i]=cur;
		cur+=BLOCK;
		fs[i]=min(n,cur-1);
		for(int j=1;j<=100;j++){
			pset[j][i]=-1;
		}
	}
	cin>>q;
	while(q--){
		cin>>l>>r>>x>>y;
		int inblock=l/BLOCK;
		if(l%BLOCK) inblock++;
		int outblock=r/BLOCK;
		if(r%BLOCK) outblock++;
		for(int i=inblock;i<=outblock;i++){
			if(x==y) continue;
			if(i==inblock || i==outblock){
				for(int j=st[i];j<=fs[i];j++){
					a[j]=fset(a[j],i);
					if(l<=j && j<=r && a[j]==x) a[j]=y;
				}
				for(int j=1;j<=100;j++) pset[j][i]=-1;
			}
			else{
				int px=fset(x,i);
				int py=fset(y,i);
				if(px==x && px==py){
					pset[y][i]=pset[x][i];
					pset[x][i]=y;
				}
				else if(px==x){
					if(py!=y){
						for(int j=st[i];j<=fs[i];j++){
							if(a[j]==y) a[j]=py;
						}
						for(int j=1;j<=100;j++){
							if(pset[j][i]==y) pset[j][i]=py;
						}
						pset[y][i]=-1;
					}
					pset[x][i]=y;
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		int inblock=i/BLOCK;
		if(i%BLOCK) inblock++;
		cout<<fset(a[i],inblock)<<" ";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int BLOCK=800;
int n,q,a[200007],pset[107][(200007/BLOCK)+3],st[100007],fs[100007];
int l,r,x,y;
int fset(int x,int num){
	if(pset[x][num]<0) return x;
	else return pset[x][num]=fset(pset[x][num],num);
}
int main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int nblock=n/BLOCK;
	if(n%BLOCK) nblock++;
	int cur=1;
	for(int i=1;i<=nblock;i++){
		st[i]=cur;
		cur+=BLOCK;
		fs[i]=min(n,cur-1);
		for(int j=1;j<=100;j++){
			pset[j][i]=-1;
		}
	}
	cin>>q;
	while(q--){
		cin>>l>>r>>x>>y;
		int inblock=l/BLOCK;
		if(l%BLOCK) inblock++;
		int outblock=r/BLOCK;
		if(r%BLOCK) outblock++;
		for(int i=inblock;i<=outblock;i++){
			if(i==inblock || i==outblock){
				for(int j=st[i];j<=fs[i];j++){
					a[j]=fset(a[j],i);
					if(l<=j && j<=r && a[j]==x) a[j]=y;
				}
				for(int j=1;j<=100;j++) pset[j][i]=-1;
			}
			else{
				int px=fset(x,i);
				int py=fset(y,i);
				if(px==x && px==py){
					pset[y][i]=pset[x][i];
					pset[x][i]=y;
				}
				else if(px==x){
					if(py!=y){
						for(int j=st[i];j<=fs[i];j++){
							if(a[j]==y) a[j]=py;
						}
						pset[y][i]=-1;
					}
					pset[x][i]=y;
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		int inblock=i/BLOCK;
		if(i%BLOCK) inblock++;
		cout<<fset(a[i],inblock)<<" ";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int BLOCK=300;
int n,q,a[200007],pset[107][(200007/BLOCK)+100],st[100007],fs[100007];
int l,r,x,y;
int fset(int x,int num){
	if(pset[x][num]<0) return x;
	else return pset[x][num]=fset(pset[x][num],num);
}
int main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int nblock=n/BLOCK;
	if(n%BLOCK) nblock++;
	int cur=1;
	for(int i=1;i<=nblock;i++){
		st[i]=cur;
		cur+=BLOCK;
		fs[i]=min(n,cur-1);
		for(int j=1;j<=100;j++){
			pset[j][i]=-1;
		}
	}
	cin>>q;
	while(q--){
		cin>>l>>r>>x>>y;
		int inblock=l/BLOCK;
		if(l%BLOCK) inblock++;
		int outblock=r/BLOCK;
		if(r%BLOCK) outblock++;
		for(int i=inblock;i<=outblock;i++){
			if(x==y) continue;
			if(i==inblock || i==outblock){
				for(int j=st[i];j<=fs[i];j++){
					a[j]=fset(a[j],i);
					if(l<=j && j<=r && a[j]==x) a[j]=y;
				}
				for(int j=1;j<=100;j++) pset[j][i]=-1;
			}
			else{
				int px=fset(x,i);
				int py=fset(y,i);
				if(px==x && px==py){
					pset[y][i]=pset[x][i];
					pset[x][i]=y;
				}
				else if(px==x){
					if(py!=y){
						for(int j=st[i];j<=fs[i];j++){
							if(a[j]==y) a[j]=py;
						}
						for(int j=1;j<=100;j++){
							if(pset[j][i]==y) pset[j][i]=py;
						}
						pset[y][i]=-1;
					}
					pset[x][i]=y;
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		int inblock=i/BLOCK;
		if(i%BLOCK) inblock++;
		cout<<fset(a[i],inblock)<<" ";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int BLOCK=300;
int n,q,a[200007],pset[107][(200007/BLOCK)+3],st[100007],fs[100007];
int l,r,x,y;
int fset(int x,int num){
	if(pset[x][num]<0) return x;
	else return pset[x][num]=fset(pset[x][num],num);
}
int main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int nblock=n/BLOCK;
	if(n%BLOCK) nblock++;
	int cur=1;
	for(int i=1;i<=nblock;i++){
		st[i]=cur;
		cur+=BLOCK;
		fs[i]=min(n,cur-1);
		for(int j=1;j<=100;j++){
			pset[j][i]=-1;
		}
	}
	cin>>q;
	while(q--){
		cin>>l>>r>>x>>y;
		int inblock=l/BLOCK;
		if(l%BLOCK) inblock++;
		int outblock=r/BLOCK;
		if(r%BLOCK) outblock++;
		for(int i=inblock;i<=outblock;i++){
			if(i==inblock || i==outblock){
				for(int j=st[i];j<=fs[i];j++){
					a[j]=fset(a[j],i);
					if(l<=j && j<=r && a[j]==x) a[j]=y;
				}
				for(int j=1;j<=100;j++) pset[j][i]=-1;
			}
			else{
				int px=fset(x,i);
				int py=fset(y,i);
				if(px==py){
					pset[x][i]=pset[px][i];
					pset[px][i]=x;
				}
				else if(px==x){
					if(py!=y){
						for(int j=st[i];j<=fs[i];j++){
							if(a[j]==y) a[j]=py;
						}
						pset[y][i]=-1;
					}
					pset[x][i]=y;
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		int inblock=i/BLOCK;
		if(i%BLOCK) inblock++;
		cout<<fset(a[i],inblock)<<" ";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int BLOCK=500;
int n,q,a[200007],pset[107][(200007/BLOCK)+100],st[100007],fs[100007];
int l,r,x,y;
int fset(int x,int num){
	if(pset[x][num]<0) return x;
	else return pset[x][num]=fset(pset[x][num],num);
}
int main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int nblock=n/BLOCK;
	if(n%BLOCK) nblock++;
	int cur=1;
	for(int i=1;i<=nblock;i++){
		st[i]=cur;
		cur+=BLOCK;
		fs[i]=min(n,cur-1);
		for(int j=1;j<=100;j++){
			pset[j][i]=-1;
		}
	}
	cin>>q;
	while(q--){
		cin>>l>>r>>x>>y;
		int inblock=l/BLOCK;
		if(l%BLOCK) inblock++;
		int outblock=r/BLOCK;
		if(r%BLOCK) outblock++;
		for(int i=inblock;i<=outblock;i++){
			if(x==y) continue;
			if(i==inblock || i==outblock){
				for(int j=st[i];j<=fs[i];j++){
					a[j]=fset(a[j],i);
					if(l<=j && j<=r && a[j]==x) a[j]=y;
				}
				for(int j=1;j<=100;j++) pset[j][i]=-1;
			}
			else{
				int px=fset(x,i);
				int py=fset(y,i);
				if(px==x && px==py){
					pset[y][i]=pset[x][i];
					pset[x][i]=y;
				}
				else if(px==x){
					if(py!=y){
						for(int j=st[i];j<=fs[i];j++){
							if(a[j]==y) a[j]=py;
						}
						for(int j=1;j<=100;j++){
							if(pset[j][i]==y) pset[j][i]=py;
						}
						pset[y][i]=-1;
					}
					pset[x][i]=y;
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		int inblock=i/BLOCK;
		if(i%BLOCK) inblock++;
		cout<<fset(a[i],inblock)<<" ";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int BLOCK=1;
int n,q,a[200007],pset[107][(200007/BLOCK)+3],st[100007],fs[100007];
int l,r,x,y;
int fset(int x,int num){
	if(pset[x][num]<0) return x;
	else return pset[x][num]=fset(pset[x][num],num);
}
int main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int nblock=n/BLOCK;
	if(n%BLOCK) nblock++;
	int cur=1;
	for(int i=1;i<=nblock;i++){
		st[i]=cur;
		cur+=BLOCK;
		fs[i]=min(n,cur-1);
		for(int j=1;j<=100;j++){
			pset[j][i]=-1;
		}
	}
	cin>>q;
	while(q--){
		cin>>l>>r>>x>>y;
		int inblock=l/BLOCK;
		if(l%BLOCK) inblock++;
		int outblock=r/BLOCK;
		if(r%BLOCK) outblock++;
		for(int i=inblock;i<=outblock;i++){
			if(i==inblock || i==outblock){
				for(int j=st[i];j<=fs[i];j++){
					a[j]=fset(a[j],i);
					if(l<=j && j<=r && a[j]==x) a[j]=y;
				}
				for(int j=1;j<=100;j++) pset[j][i]=-1;
			}
			else{
				int px=fset(x,i);
				int py=fset(y,i);
				if(px==x && px==py){
					pset[y][i]=pset[x][i];
					pset[x][i]=y;
				}
				else if(px==x){
					if(py!=y){
						for(int j=st[i];j<=fs[i];j++){
							if(a[j]==y) a[j]=py;
						}
						pset[y][i]=-1;
					}
					pset[x][i]=y;
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		int inblock=i/BLOCK;
		if(i%BLOCK) inblock++;
		cout<<fset(a[i],inblock)<<" ";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int BLOCK=1000;
int n,q,a[200007],pset[107][(200007/BLOCK)+100],st[100007],fs[100007];
int l,r,x,y;
int fset(int x,int num){
	if(pset[x][num]<0) return x;
	else return pset[x][num]=fset(pset[x][num],num);
}
int main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int nblock=n/BLOCK;
	if(n%BLOCK) nblock++;
	int cur=1;
	for(int i=1;i<=nblock;i++){
		st[i]=cur;
		cur+=BLOCK;
		fs[i]=min(n,cur-1);
		for(int j=1;j<=100;j++){
			pset[j][i]=-1;
		}
	}
	cin>>q;
	while(q--){
		cin>>l>>r>>x>>y;
		int inblock=l/BLOCK;
		if(l%BLOCK) inblock++;
		int outblock=r/BLOCK;
		if(r%BLOCK) outblock++;
		for(int i=inblock;i<=outblock;i++){
			if(x==y) continue;
			if(i==inblock || i==outblock){
				for(int j=st[i];j<=fs[i];j++){
					a[j]=fset(a[j],i);
					if(l<=j && j<=r && a[j]==x) a[j]=y;
				}
				for(int j=1;j<=100;j++) pset[j][i]=-1;
			}
			else{
				int px=fset(x,i);
				int py=fset(y,i);
				if(px==x && px==py){
					pset[y][i]=pset[x][i];
					pset[x][i]=y;
				}
				else if(px==x){
					if(py!=y){
						for(int j=st[i];j<=fs[i];j++){
							if(a[j]==y) a[j]=py;
						}
						for(int j=1;j<=100;j++){
							if(pset[j][i]==y) pset[j][i]=py;
						}
						pset[y][i]=-1;
					}
					pset[x][i]=y;
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		int inblock=i/BLOCK;
		if(i%BLOCK) inblock++;
		cout<<fset(a[i],inblock)<<" ";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int BLOCK=700;
int n,q,a[200007],pset[107][(200007/BLOCK)+100],st[100007],fs[100007];
int l,r,x,y;
int fset(int x,int num){
	if(pset[x][num]<0) return x;
	else return pset[x][num]=fset(pset[x][num],num);
}
int main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int nblock=n/BLOCK;
	if(n%BLOCK) nblock++;
	int cur=1;
	for(int i=1;i<=nblock;i++){
		st[i]=cur;
		cur+=BLOCK;
		fs[i]=min(n,cur-1);
		for(int j=1;j<=100;j++){
			pset[j][i]=-1;
		}
	}
	cin>>q;
	while(q--){
		cin>>l>>r>>x>>y;
		int inblock=l/BLOCK;
		if(l%BLOCK) inblock++;
		int outblock=r/BLOCK;
		if(r%BLOCK) outblock++;
		for(int i=inblock;i<=outblock;i++){
			if(x==y) continue;
			if(i==inblock || i==outblock){
				for(int j=st[i];j<=fs[i];j++){
					a[j]=fset(a[j],i);
					if(l<=j && j<=r && a[j]==x) a[j]=y;
				}
				for(int j=1;j<=100;j++) pset[j][i]=-1;
			}
			else{
				int px=fset(x,i);
				int py=fset(y,i);
				if(px==x && px==py){
					pset[y][i]=pset[x][i];
					pset[x][i]=y;
				}
				else if(px==x){
					if(py!=y){
						for(int j=st[i];j<=fs[i];j++){
							a[j]=fset(a[j],i);
						}
						for(int j=1;j<=100;j++){
							pset[j][i]=-1;
						}
					}
					pset[x][i]=y;
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		int inblock=i/BLOCK;
		if(i%BLOCK) inblock++;
		cout<<fset(a[i],inblock)<<" ";
	}
}


/*input
5
1 2 3 4 5
3
3 5 3 5
1 5 5 1
1 5 1 5
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie() , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define MAX 200090
#define INF 0x3f3f3f3f
#define N 100
#define ls (now << 1)
#define rs (now << 1 | 1)
#define mid ((l + r) >> 1)

int tag[MAX * 4][102];
vector<int> ll[102] , rr[102];
void Push(int now , int l , int r){
	if(l == r) return;
	REP(i , 1 , N + 1) ll[i].clear() , rr[i].clear();
	REP(i , 1 , N + 1){
		if(tag[ls][i]) ll[tag[ls][i]].pb(i);
		if(tag[rs][i]) rr[tag[rs][i]].pb(i);
	}

	REP(i , 1 , N + 1){
		if(tag[now][i]){
			if(tag[ls][i] == 0) tag[ls][i] = tag[now][i];
			if(tag[rs][i] == 0) tag[rs][i] = tag[now][i];
			for(auto to : ll[i]) tag[ls][to] = tag[now][i];
			for(auto to : rr[i]) tag[rs][to] = tag[now][i];
			tag[now][i] = 0;
		}
	}
}
void update(int now , int l , int r , int ql , int qr , int a , int b){
	Push(now , l , r);
	if(ql <= l && r <= qr){
		tag[now][a] = b;
	}
	else {
		if(ql <= mid + 0) update(ls , l , mid + 0 , ql , qr , a , b);
		if(mid + 1 <= qr) update(rs , mid + 1 , r , ql , qr , a , b);
	}
}
int n , m , x[MAX] , ans[MAX];
void Print(int now , int l , int r){
	if(l == r) ans[l] = tag[now][x[l]];
	else {
		Push(now , l , r);
		Print(ls , l , mid + 0);
		Print(rs , mid + 1 , r);
	}
}
int32_t main(){
	IOS;
	cin >> n;
	REP(i , 1 , n + 1) cin >> x[i];
	cin >> m;

	REP(i , 1 , N + 1) tag[1][i] = i;

	Print(1 , 1 , n);
	REP(i , 1 , m + 1){
		int l , r , a , b;
		cin >> l >> r >> a >> b;
		update(1 , 1 , n , l , r , a , b);
	}
	Print(1 , 1 , n);
	REP(i , 1 , n + 1) cout << ans[i] << " "; cout << endl;
    return 0;
}


/*input
5
1 2 3 4 5
3
3 5 3 5
1 5 5 1
1 5 1 5
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie(0) , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define MAX 200900
#define INF 0x3f3f3f3f

struct N{
	int pri , val , sml;
	N *l , *r;
	N(int _val){
		pri = rand() << 16 | rand();
		val = sml = _val;
		l = r = NULL;
	}
};
int SML(N *now){ return now ? now->sml : INF; }
void Pull(N *now){ now->sml = min(now->val , min(SML(now->l) , SML(now->r))); }
N *Merge(N *a , N *b){
	if(!a || !b) return a ? a : b;
	if(a->pri > b->pri)
		 return a->r = Merge(a->r , b) , Pull(a) , a;
	else return b->l = Merge(a , b->l) , Pull(b) , b;
}
void Split(N *t , int v , N *&a , N *&b){
	if(!t) return a = b = NULL , void();
	if(t->val <= v)
		 a = t , Split(t->r , v , a->r , b);
	else b = t , Split(t->l , v , a , b->l);
	Pull(t);
}
int n , m , x[MAX] , ans[MAX];
N *root[200];
void put(N *now){
	if(!now) return ;
	cout << now->val << " ";
	if(now->l) put(now->l);
	if(now->r) put(now->r);
}
N *Join(N *a , N *b){
	if(!a || !b) return a ? a : b;
	if(a->sml > b->sml) swap(a , b);
	N *left , *right;
	Split(a , SML(b) , left , right);
	return Join(right , Merge(left , b));
}
void Print(int val , N *now){
	if(!now) return;
	ans[now->val] = val;
	if(now->l) Print(val , now->l);
	if(now->r) Print(val , now->r);
}
int32_t main(){
	IOS;
	cin >> n;
	REP(i , 1 , n + 1) cin >> x[i];
	REP(i , 1 , n + 1) root[x[i]] = Merge(root[x[i]] , new N(i));
	cin >> m;
	REP(i , 1 , m + 1){
		int l , r , a , b;
		cin >> l >> r >> a >> b;
		N *left1 , *mid1 , *right1 , *tmp1;
		N *left2 , *mid2 , *right2 , *tmp2;
		Split(root[a] , r , tmp1 , right1);
		Split(tmp1 , l - 1 , left1 , mid1);

		Split(root[b] , r , tmp2 , right2);
		Split(tmp2 , l - 1 , left2 , mid2);
		root[a] = Merge(left1 , right1);
		root[b] = Merge(left2 , Merge(Join(mid1 , mid2) , right2));
	}
	REP(i , 1 , 100 + 1) Print(i , root[i]);
	REP(i , 1 , n + 1) cout << ans[i] << " "; cout << endl;
    return 0;
}


/*input
5
1 2 3 4 5
3
3 5 3 5
1 5 5 1
1 5 1 5
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie() , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define MAX 200900
#define INF 0x3f3f3f3f

typedef tree<int,null_type,greater<int>,rb_tree_tag,tree_order_statistics_node_update> TREE;
TREE tr[110];
int n , m , x[MAX] , ans[MAX];
int32_t main(){
	IOS;
	cin >> n;
	REP(i , 1 , n + 1) cin >> x[i];
	REP(i , 1 , n + 1) tr[x[i]].insert(i);
	cin >> m;
	REP(i , 1 , m + 1){
		int l , r , a , b;
		cin >> l >> r >> a >> b;
		TREE tma , tmb;
		tr[a].split(r + 1 , tma);
		tma.split(l , tmb);
		tr[a].join(tmb);
		tr[b].join(tma);
	}
	REP(i , 1 , 100 + 1){
		for(auto to : tr[i]) ans[to] = i;
	}
	REP(i , 1 , n + 1) cout << ans[i] << " "; cout << endl;
    return 0;
}


/*input
5
1 2 3 4 5
3
3 5 3 5
1 5 5 1
1 5 1 5
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie(0) , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define MAX 200900
#define INF 0x3f3f3f3f

struct N{
	int pri , val , sml;
	N *l , *r;
	N(int _val){
		pri = rand() << 16 | rand();
		val = sml = _val;
		l = r = NULL;
	}
};
int SML(N *now){ return now ? now->sml : INF; }
void Pull(N *now){ now->sml = min(now->val , min(SML(now->l) , SML(now->r))); }
N *Merge(N *a , N *b){
	if(!a || !b) return a ? a : b;
	if(a->pri > b->pri)
		 return a->r = Merge(a->r , b) , Pull(a) , a;
	else return b->l = Merge(a , b->l) , Pull(b) , b;
}
void Split(N *t , int v , N *&a , N *&b){
	if(!t) return a = b = NULL , void();
	if(t->val <= v)
		 a = t , Split(t->r , v , a->r , b);
	else b = t , Split(t->l , v , a , b->l);
	Pull(t);
}
int n , m , x[MAX] , ans[MAX];
N *root[200];
void put(N *now){
	if(!now) return ;
	cout << now->val << " ";
	if(now->l) put(now->l);
	if(now->r) put(now->r);
}
N *Join(N *a , N *b){
	if(!a || !b) return a ? a : b;
	if(a->sml > b->sml) swap(a , b);
	N *left , *right;
	Split(a , SML(b) , left , right);
	return Join(right , Merge(left , b));
}
void Print(int val , N *now){
	if(!now) return;
	ans[now->val] = val;
	if(now->l) Print(val , now->l);
	if(now->r) Print(val , now->r);
}
int32_t main(){
	IOS;
	cin >> n;
	REP(i , 1 , n + 1) cin >> x[i];
	REP(i , 1 , n + 1) root[x[i]] = Merge(root[x[i]] , new N(i));
	cin >> m;
	REP(i , 1 , m + 1){
		int l , r , a , b;
		cin >> l >> r >> a >> b;
		N *left1 , *mid1 , *right1 , *tmp1;
		N *left2 , *mid2 , *right2 , *tmp2;
		Split(root[a] , r , tmp1 , right1);
		Split(tmp1 , l - 1 , left1 , mid1);

		Split(root[b] , r , tmp2 , right2);
		Split(tmp2 , l - 1 , left2 , mid2);
		root[a] = Merge(left1 , right1);
		root[b] = Merge(left1 , Merge(Join(mid1 , mid2) , right2));
	}
	REP(i , 1 , 100 + 1) Print(i , root[i]);
	REP(i , 1 , n + 1) cout << ans[i] << " "; cout << endl;
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int compare (const void * a, const void * b)
{
  return ( *(int*)a - *(int*)b );
}

int main() {
    int* a;
    int n;
    int k;
    int res;
    int min = 1000000;
    int i;

    scanf("%d", &n);
    scanf("%d", &k);

    a = (int*)malloc(n * sizeof(int));

    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }

    qsort (a, n, sizeof(int), compare);

    res = a[0];

    while (res > 1) {
        for (i = 0; i < n; i++) {
            if ((a[i] % res) > k) {
                res = a[i] / (a[i] / res + 1);
                break;
            }
        }

        if (i == n) {
            goto R;
        }
    }
    R:
    printf("%d", res);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

    int main() {
        int* a;
        int n;
        int k;
        int res;
        int min = 1000000;
        int i;

        scanf("%d", &n);
        scanf("%d", &k);
        a = (int*)malloc(n*sizeof(int));

        for (i = 0; i < n; i++) {
            scanf("%d", &a[i]);
            if (min > a[i]) min = a[i];
        }

        res = min;

        while (res > 1) {
            for (i = 0; i < n; i++) {
                if ((a[i] % res) > k) {
                    goto Z;
                }
            }

            if (i == n) {
                goto R;
            }
            Z:
            res--;
        }
        R:
        printf("%d", res);
        return 0;
    }


#include <stdio.h>
#define MAXV 1000000

int v[3 * 100005];
int count[2 * 1000005];

int main(void) {
    int n, k;

    int i, j;
    int best;
    int aux;

    scanf(" %d %d", &n, &k);

    for (i = 0; i < n; i++) {
        scanf(" %d", &v[i]);
        count[v[i]]++;
    }

    for (i = 1; i <= 2 * MAXV; i++) {
        count[i] += count[i - 1];
    }

    best = 1;
    for (i = 1; i <= MAXV; i++) {
        aux = 0;
        for (j = 1; j * i + k <= 2 * MAXV; j++) {
            aux += count[j * i + k] - count[j * i - 1];
        }
        if (aux == n) {
            best = i;
        }
    }

    printf("%d\n", best);

    return 0;
}


#include <stdio.h>
#define INF 0x3f3f3f3f
#define MAXV 1000000

int v[3 * 100005];
int count[2 * 1000005];

int main(void) {
    int n, k;

    int i, j;
    int best;
    int aux;
    int min;

    scanf(" %d %d", &n, &k);

    min = INF;
    for (i = 0; i < n; i++) {
        scanf(" %d", &v[i]);
        if (v[i] < min) {
            min = v[i];
        }
        count[v[i]]++;
    }

    for (i = 1; i <= 2 * MAXV; i++) {
        count[i] += count[i - 1];
    }

    if (min <= k + 1) {
        best = min;
    } else {
        best = 1;
        for (i = MAXV; i >= 1; i--) {
            aux = 0;
            for (j = 1; j * i + k <= 2 * MAXV; j++) {
                aux += count[j * i + k] - count[j * i - 1];
            }
            if (aux == n) {
                best = i;
                break;
            }
        }
    }

    printf("%d\n", best);

    return 0;
}


import java.util.*;
import java.io.*;

public class _0355_E_VasyaAndBeautifulArrays {

	public static void main(String[] args) throws IOException {
		int N = readInt(), K = readInt();
		Integer arr[] = new Integer[N];
		for(int i = 0; i<N; i++) arr[i] = readInt();
		Arrays.sort(arr);
//		for(int n : arr) print(n + " ");
//		println();
		int val[] = new int[2000001]; int idx = K;
		for(int i = K+1; i<=2000000; i++) {
			while(idx < N && arr[idx] <= i) idx++;
			val[i] = idx;
		}
		int ans = 1;
		for(int i = 1; i<=arr[0]; i++) {
			idx = val[i];
			for(int j = 0; j<=2000000/i; j++) {
				idx = val[j*i+K];
				if(idx == N) break;
				if(arr[idx]%i > K) break;
//				println(idx + " " + i);
			}
			if(idx == N) ans = i;
		}
		println(ans);
		exit();
	}

	final private static int BUFFER_SIZE = 1 << 16;
	private static DataInputStream din = new DataInputStream(System.in);
	private static byte[] buffer = new byte[BUFFER_SIZE];
	private static int bufferPointer = 0, bytesRead = 0;
	static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

	public static String readLine() throws IOException {
		byte[] buf = new byte[64]; // line length
		int cnt = 0, c;
		while ((c = Read()) != -1) {
			if (c == '\n')
				break;
			buf[cnt++] = (byte) c;
		}
		return new String(buf, 0, cnt);
	}

	public static String read() throws IOException {
		byte[] ret = new byte[1024];
		int idx = 0;
		byte c = Read();
		while (c <= ' ') {
			c = Read();
		}
		do {
			ret[idx++] = c;
			c = Read();
		} while (c != -1 && c != ' ' && c != '\n' && c != '\r');
		return new String(ret, 0, idx);
	}

	public static int readInt() throws IOException {
		int ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (neg)
			return -ret;
		return ret;
	}

	public static long readLong() throws IOException {
		long ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');
		if (neg)
			return -ret;
		return ret;
	}

	public static double readDouble() throws IOException {
		double ret = 0, div = 1;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();

		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (c == '.') {
			while ((c = Read()) >= '0' && c <= '9') {
				ret += (c - '0') / (div *= 10);
			}
		}

		if (neg)
			return -ret;
		return ret;
	}

	private static void fillBuffer() throws IOException {
		bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
		if (bytesRead == -1)
			buffer[0] = -1;
	}

	private static byte Read() throws IOException {
		if (bufferPointer == bytesRead)
			fillBuffer();
		return buffer[bufferPointer++];
	}

	static void print(Object o) {
		pr.print(o);
	}

	static void println(Object o) {
		pr.println(o);
	}

	static void flush() {
		pr.flush();
	}

	static void println() {
		pr.println();
	}

	static void exit() throws IOException {
		din.close();
		pr.close();
		System.exit(0);
	}
}


import java.util.*;
import java.io.*;

public class _0355_E_VasyaAndBeautifulArrays {

	public static void main(String[] args) throws IOException {
		int N = readInt(), K = readInt();
		Integer arr[] = new Integer[N];
		for(int i = 0; i<N; i++) arr[i] = readInt();
		Arrays.sort(arr);
//		for(int n : arr) print(n + " ");
//		println();
		int val[] = new int[2000001]; int idx = 0;
		for(int i = 1; i<=2000000; i++) {
			while(idx < N && arr[idx] <= i) idx++;
			val[i] = idx;
		}
		int ans = 1;
		for(int i = 1; i<=arr[0]; i++) {
			for(int j = 0; j<=2000000/i; j++) {
				idx = val[j*i+K];
				if(idx == N) break;
				if(arr[idx]%i > K) break;
//				println(idx + " " + i);
			}
			if(idx == N) ans = i;
		}
		println(ans);
		exit();
	}

	final private static int BUFFER_SIZE = 1 << 16;
	private static DataInputStream din = new DataInputStream(System.in);
	private static byte[] buffer = new byte[BUFFER_SIZE];
	private static int bufferPointer = 0, bytesRead = 0;
	static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

	public static String readLine() throws IOException {
		byte[] buf = new byte[64]; // line length
		int cnt = 0, c;
		while ((c = Read()) != -1) {
			if (c == '\n')
				break;
			buf[cnt++] = (byte) c;
		}
		return new String(buf, 0, cnt);
	}

	public static String read() throws IOException {
		byte[] ret = new byte[1024];
		int idx = 0;
		byte c = Read();
		while (c <= ' ') {
			c = Read();
		}
		do {
			ret[idx++] = c;
			c = Read();
		} while (c != -1 && c != ' ' && c != '\n' && c != '\r');
		return new String(ret, 0, idx);
	}

	public static int readInt() throws IOException {
		int ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (neg)
			return -ret;
		return ret;
	}

	public static long readLong() throws IOException {
		long ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');
		if (neg)
			return -ret;
		return ret;
	}

	public static double readDouble() throws IOException {
		double ret = 0, div = 1;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();

		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (c == '.') {
			while ((c = Read()) >= '0' && c <= '9') {
				ret += (c - '0') / (div *= 10);
			}
		}

		if (neg)
			return -ret;
		return ret;
	}

	private static void fillBuffer() throws IOException {
		bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
		if (bytesRead == -1)
			buffer[0] = -1;
	}

	private static byte Read() throws IOException {
		if (bufferPointer == bytesRead)
			fillBuffer();
		return buffer[bufferPointer++];
	}

	static void print(Object o) {
		pr.print(o);
	}

	static void println(Object o) {
		pr.println(o);
	}

	static void flush() {
		pr.flush();
	}

	static void println() {
		pr.println();
	}

	static void exit() throws IOException {
		din.close();
		pr.close();
		System.exit(0);
	}
}


import java.util.*;
import java.io.*;

public class _0355_E_VasyaAndBeautifulArrays {

	public static void main(String[] args) throws IOException {
		int N = readInt(), K = readInt();
		Integer arr[] = new Integer[N];
		for(int i = 0; i<N; i++) arr[i] = readInt()+K;
		Arrays.sort(arr);
		int val[] = new int[2000001]; int idx = 0;
		for(int i = 1; i<=2000000; i++) {
			while(idx < N && arr[idx] <= i) idx++;
			val[i] = idx;
		}
		int ans = 2*K+1;
		for(int i = 2*K+2; i<=2000000; i++) {
			if(arr[0] < i) {println(ans); exit();}
			idx = 0;
			for(int j = 1; j<=2000000/i; i++) {
				idx = val[j*i];
				if(idx == N) break;
				if(arr[idx]%i > 2*K) break;
			}
			if(idx == N) ans = i;
		}
		println(ans);
		exit();
	}

	final private static int BUFFER_SIZE = 1 << 16;
	private static DataInputStream din = new DataInputStream(System.in);
	private static byte[] buffer = new byte[BUFFER_SIZE];
	private static int bufferPointer = 0, bytesRead = 0;
	static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

	public static String readLine() throws IOException {
		byte[] buf = new byte[64]; // line length
		int cnt = 0, c;
		while ((c = Read()) != -1) {
			if (c == '\n')
				break;
			buf[cnt++] = (byte) c;
		}
		return new String(buf, 0, cnt);
	}

	public static String read() throws IOException {
		byte[] ret = new byte[1024];
		int idx = 0;
		byte c = Read();
		while (c <= ' ') {
			c = Read();
		}
		do {
			ret[idx++] = c;
			c = Read();
		} while (c != -1 && c != ' ' && c != '\n' && c != '\r');
		return new String(ret, 0, idx);
	}

	public static int readInt() throws IOException {
		int ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (neg)
			return -ret;
		return ret;
	}

	public static long readLong() throws IOException {
		long ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');
		if (neg)
			return -ret;
		return ret;
	}

	public static double readDouble() throws IOException {
		double ret = 0, div = 1;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();

		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (c == '.') {
			while ((c = Read()) >= '0' && c <= '9') {
				ret += (c - '0') / (div *= 10);
			}
		}

		if (neg)
			return -ret;
		return ret;
	}

	private static void fillBuffer() throws IOException {
		bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
		if (bytesRead == -1)
			buffer[0] = -1;
	}

	private static byte Read() throws IOException {
		if (bufferPointer == bytesRead)
			fillBuffer();
		return buffer[bufferPointer++];
	}

	static void print(Object o) {
		pr.print(o);
	}

	static void println(Object o) {
		pr.println(o);
	}

	static void flush() {
		pr.flush();
	}

	static void println() {
		pr.println();
	}

	static void exit() throws IOException {
		din.close();
		pr.close();
		System.exit(0);
	}
}


import java.util.*;
import java.io.*;

public class _0355_E_VasyaAndBeautifulArrays {

	public static void main(String[] args) throws IOException {
		int N = readInt(), K = readInt();
		Integer arr[] = new Integer[N];
		for(int i = 0; i<N; i++) arr[i] = readInt()+K;
		Arrays.sort(arr);
		int val[] = new int[2000001]; int idx = 0;
		for(int i = 1; i<=2000000; i++) {
			while(idx < N && arr[idx] <= i) idx++;
			val[i] = idx;
		}
		int ans = 1;
		for(int i = 1; i<=arr[0]-K; i++) {
			if(arr[0] < i) {println(ans); exit();}
			idx = 0;
			for(int j = 2; j<=2000000/i; j++) {
				idx = val[j*i];
				if(idx == N) break;
				if(arr[idx]%i > 2*K) break;
			}
			if(idx == N) ans = i;
		}
		println(ans);
		exit();
	}

	final private static int BUFFER_SIZE = 1 << 16;
	private static DataInputStream din = new DataInputStream(System.in);
	private static byte[] buffer = new byte[BUFFER_SIZE];
	private static int bufferPointer = 0, bytesRead = 0;
	static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

	public static String readLine() throws IOException {
		byte[] buf = new byte[64]; // line length
		int cnt = 0, c;
		while ((c = Read()) != -1) {
			if (c == '\n')
				break;
			buf[cnt++] = (byte) c;
		}
		return new String(buf, 0, cnt);
	}

	public static String read() throws IOException {
		byte[] ret = new byte[1024];
		int idx = 0;
		byte c = Read();
		while (c <= ' ') {
			c = Read();
		}
		do {
			ret[idx++] = c;
			c = Read();
		} while (c != -1 && c != ' ' && c != '\n' && c != '\r');
		return new String(ret, 0, idx);
	}

	public static int readInt() throws IOException {
		int ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (neg)
			return -ret;
		return ret;
	}

	public static long readLong() throws IOException {
		long ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');
		if (neg)
			return -ret;
		return ret;
	}

	public static double readDouble() throws IOException {
		double ret = 0, div = 1;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();

		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (c == '.') {
			while ((c = Read()) >= '0' && c <= '9') {
				ret += (c - '0') / (div *= 10);
			}
		}

		if (neg)
			return -ret;
		return ret;
	}

	private static void fillBuffer() throws IOException {
		bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
		if (bytesRead == -1)
			buffer[0] = -1;
	}

	private static byte Read() throws IOException {
		if (bufferPointer == bytesRead)
			fillBuffer();
		return buffer[bufferPointer++];
	}

	static void print(Object o) {
		pr.print(o);
	}

	static void println(Object o) {
		pr.println(o);
	}

	static void flush() {
		pr.flush();
	}

	static void println() {
		pr.println();
	}

	static void exit() throws IOException {
		din.close();
		pr.close();
		System.exit(0);
	}
}


import java.util.*;
import java.io.*;

public class E
{

    Reader in;
    PrintWriter out;
    int i = 0, j = 0;
    void solve()
    {

        //START//
        int n = in.nextInt(), k = in.nextInt();
        int[] a = new int[n];
        for (i = 0; i < n; i++)
        {
            a[i] = in.nextInt();
        }
        Arrays.sort(a);
        int sol = a[0];
        boolean done = false;
        while (!done)
        {
            done = true;
            for (i = n-1; i >= 0; i--)
            {
                while (a[i] % sol > k)
                {
                    sol--;
                    done = false;
                }
            }
        }
        out.println(sol);

        //END

    }
    void runIO()
    {
        in = new Reader();
        out = new PrintWriter(System.out, false);
        solve();
        out.close();
    }

    public static void main(String[] args)
    {
        new E().runIO();
    }

    // input/output
    static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);

            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public final String next()
        {
            int c = read();
            while (isSpaceChar(c))
            {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do
            {
                res.append((char) c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        private boolean isSpaceChar(int c)
        {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int nextInt()
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong()
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble()
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (c == '.')
                while ((c = read()) >= '0' && c <= '9')
                    ret += (c - '0') / (div *= 10);
            if (neg)
                return -ret;
            return ret;
        }

        public int[] readIntArray(int size)
        {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++)
                arr[i] = nextInt();
            return arr;
        }

        public long[] readLongArray(int size)
        {
            long[] arr = new long[size];
            for (int i = 0; i < size; i++)
                arr[i] = nextInt();
            return arr;
        }

        private void fillBuffer()
        {
            try
            {
                bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            }
            catch (IOException e)
            {

            }

            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read()
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }
    }
}


import java.util.*;
import java.io.*;
import java.math.*;
public class Main {

    PrintWriter out = new PrintWriter(System.out);
    InputReader ir = new InputReader(System.in);
    final long kmod = 993960000099397l;
    int arr[];
    int hash[];
    void solve() throws IOException{
        int n = ir.readInt();
        int k = ir.readInt();
        hash = new int[2200001];
        arr = new int[n];
        int min = Integer.MAX_VALUE;
        for(int i = 0; i < n; i++) {
            arr[i] = ir.readInt();
            hash[arr[i]] = 1;
            min = Math.min(min, arr[i]);
        }
        for(int i = 2; i <= 2200000; i++) {
            hash[i] += hash[i - 1];
        }

        for(int i = min; i >= 1; i--) {
            if(check(i, k)) {
                out.println(i);
                return;
            }
        }

    }

    boolean check(int num, int k) {
        if(num <= k)
            return true;

        int prev = 0;
        for(int i = num; i <= 2200000; i += num) {
            if(hash[i - 1] - hash[prev + k] != 0) {
                return false;
            }
            prev = i;
        }
        return true;
    }

    void run() throws IOException{
        solve();
        out.close();
    }
    public static void main(String args[]) throws IOException{
        new Main().run();
    }
}
class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }
    public final int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
    }
    public long readLong() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String readString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return isWhitespace(c);
    }
        public double readDouble() {
        return Double.parseDouble(readString());
    }

    public static boolean isWhitespace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public String next() {
        return readString();
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}


import java.util.*;
import java.io.*;
import java.math.*;
public class Main {

    PrintWriter out = new PrintWriter(System.out);
    InputReader ir = new InputReader(System.in);
    final long kmod = 993960000099397l;
    int arr[];
    void solve() throws IOException{
        int n = ir.readInt();
        int k = ir.readInt();
        arr = new int[n];
        int min = Integer.MAX_VALUE;
        for(int i = 0; i < n; i++) {
            arr[i] = ir.readInt();
            min = Math.min(min, arr[i]);
        }
        int gcd = arr[0];
        for(int i = 1; i < n; i++) {
            gcd = gcd(gcd, arr[i]);
        }
        int start = Math.max(1, min - k);
        int end = min;
        for(int i = min; i >= start; i--){
            if(fun(i, k)) {
                out.println(Math.max(i, gcd));
                return;
            }
        }

    }
    int gcd(int a, int b) {
        if(b == 0)
            return a;
        return gcd(b, a % b);
    }
    boolean fun(int num, int k) {
        int n = arr.length;
        for(int i = 0; i < n; i++) {
            int rem = (arr[i] % num);
            if(rem > k)
                return false;
        }
        return true;
    }

    void run() throws IOException{
        solve();
        out.close();
    }
    public static void main(String args[]) throws IOException{
        new Main().run();
    }
}
class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }
    public final int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
    }
    public long readLong() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String readString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return isWhitespace(c);
    }
        public double readDouble() {
        return Double.parseDouble(readString());
    }

    public static boolean isWhitespace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public String next() {
        return readString();
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}


import java.util.*;
import java.io.*;
import java.math.*;
public class Main {

    PrintWriter out = new PrintWriter(System.out);
    InputReader ir = new InputReader(System.in);
    final long kmod = 993960000099397l;
    int arr[];
    void solve() throws IOException{
        int n = ir.readInt();
        int k = ir.readInt();
        arr = new int[n];
        int min = Integer.MAX_VALUE;
        for(int i = 0; i < n; i++) {
            arr[i] = ir.readInt();
            min = Math.min(min, arr[i]);
        }
        int gcd = arr[0];
        for(int i = 1; i < n; i++) {
            gcd = gcd(gcd, arr[i]);
        }
        int start = Math.max(1, min - k);
        int end = min;
        for(int i = min; i >= 1; i--){
            if(fun(i, k)) {
                out.println(Math.max(i, gcd));
                return;
            }
        }

    }
    int gcd(int a, int b) {
        if(b == 0)
            return a;
        return gcd(b, a % b);
    }
    boolean fun(int num, int k) {
        int n = arr.length;
        for(int i = 0; i < n; i++) {
            int rem = (arr[i] % num);
            if(rem > k)
                return false;
        }
        return true;
    }

    void run() throws IOException{
        solve();
        out.close();
    }
    public static void main(String args[]) throws IOException{
        new Main().run();
    }
}
class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }
    public final int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
    }
    public long readLong() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String readString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return isWhitespace(c);
    }
        public double readDouble() {
        return Double.parseDouble(readString());
    }

    public static boolean isWhitespace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public String next() {
        return readString();
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}


import java.util.*;
import java.io.*;
import java.math.*;
public class Main {

    PrintWriter out = new PrintWriter(System.out);
    InputReader ir = new InputReader(System.in);
    final long kmod = 993960000099397l;
    int arr[];
    void solve() throws IOException{
        int n = ir.readInt();
        int k = ir.readInt();
        arr = new int[n];
        int min = Integer.MAX_VALUE;
        for(int i = 0; i < n; i++) {
            arr[i] = ir.readInt();
            min = Math.min(min, arr[i]);
        }
        int gcd = arr[0];
        for(int i = 1; i < n; i++) {
            gcd = gcd(gcd, arr[i]);
        }
        int start = Math.max(1, min - k);
        int end = min;
        while(start < end) {
            int mid = (start + end + 1)/2;
            if(fun(mid, k)) {
                start = mid;
            } else {
                end = mid - 1;
            }
        }
        out.println(Math.max(start, gcd));
    }
    int gcd(int a, int b) {
        if(b == 0)
            return a;
        return gcd(b, a % b);
    }
    boolean fun(int num, int k) {
        int n = arr.length;
        for(int i = 0; i < n; i++) {
            int rem = (arr[i] % num);
            if(rem > k)
                return false;
        }
        return true;
    }

    void run() throws IOException{
        solve();
        out.close();
    }
    public static void main(String args[]) throws IOException{
        new Main().run();
    }
}
class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }
    public final int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
    }
    public long readLong() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String readString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return isWhitespace(c);
    }
        public double readDouble() {
        return Double.parseDouble(readString());
    }

    public static boolean isWhitespace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public String next() {
        return readString();
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}


import java.util.*;
import java.io.*;
import java.math.*;
public class Main {

    PrintWriter out = new PrintWriter(System.out);
    InputReader ir = new InputReader(System.in);
    final long kmod = 993960000099397l;
    int arr[];
    void solve() throws IOException{
        int n = ir.readInt();
        int k = ir.readInt();
        arr = new int[n];
        int min = Integer.MAX_VALUE;
        for(int i = 0; i < n; i++) {
            arr[i] = ir.readInt();
            min = Math.min(min, arr[i]);
        }
        int gcd = arr[0];
        for(int i = 1; i < n; i++) {
            gcd = gcd(gcd, arr[i]);
        }
        int start = 1;
        int end = min;
        while(start < end) {
            int mid = (start + end + 1)/2;
            if(fun(mid, k)) {
                start = mid;
            } else {
                end = mid - 1;
            }
        }
        out.println(Math.max(start, gcd));
    }
    int gcd(int a, int b) {
        if(b == 0)
            return a;
        return gcd(b, a % b);
    }
    boolean fun(int num, int k) {
        int n = arr.length;
        for(int i = 0; i < n; i++) {
            int rem = (arr[i] % num);
            if(rem > k)
                return false;
        }
        return true;
    }

    void run() throws IOException{
        solve();
        out.close();
    }
    public static void main(String args[]) throws IOException{
        new Main().run();
    }
}
class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }
    public final int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
    }
    public long readLong() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String readString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return isWhitespace(c);
    }
        public double readDouble() {
        return Double.parseDouble(readString());
    }

    public static boolean isWhitespace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public String next() {
        return readString();
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}


import java.util.*;
import java.io.*;
import java.math.*;
public class Main {

    PrintWriter out = new PrintWriter(System.out);
    InputReader ir = new InputReader(System.in);
    final long kmod = 993960000099397l;
    int arr[];
    void solve() throws IOException{
        int n = ir.readInt();
        int k = ir.readInt();
        arr = new int[n];
        int min = Integer.MAX_VALUE;
        for(int i = 0; i < n; i++) {
            arr[i] = ir.readInt();
            min = Math.min(min, arr[i]);
        }

        int start = Math.max(1, min - k);
        int end = min;
        while(start < end) {
            int mid = (start + end + 1)/2;
            if(fun(mid, k)) {
                start = mid;
            } else {
                end = mid - 1;
            }
        }
        out.println(start);
    }
    boolean fun(int num, int k) {
        int n = arr.length;
        for(int i = 0; i < n; i++) {
            int rem = (arr[i] % num);
            if(rem > k)
                return false;
        }
        return true;
    }

    void run() throws IOException{
        solve();
        out.close();
    }
    public static void main(String args[]) throws IOException{
        new Main().run();
    }
}
class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }
    public final int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
    }
    public long readLong() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String readString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return isWhitespace(c);
    }
        public double readDouble() {
        return Double.parseDouble(readString());
    }

    public static boolean isWhitespace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public String next() {
        return readString();
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}


import java.util.*;
import java.io.*;
import java.math.*;
public class Main {

    PrintWriter out = new PrintWriter(System.out);
    InputReader ir = new InputReader(System.in);
    final long kmod = 993960000099397l;
    int arr[];
    int hash[];
    void solve() throws IOException{
        int n = ir.readInt();
        int k = ir.readInt();
        hash = new int[2200001];
        arr = new int[n];
        int min = Integer.MAX_VALUE;
        for(int i = 0; i < n; i++) {
            arr[i] = ir.readInt();
            hash[arr[i]] = 1;
            min = Math.min(min, arr[i]);
        }
        for(int i = 2; i <= 1000000; i++) {
            hash[i] += hash[i - 1];
        }

        for(int i = min; i >= 1; i--) {
            if(check(i, k)) {
                out.println(i);
                return;
            }
        }

    }

    boolean check(int num, int k) {
        if(num <= k)
            return true;

        int prev = 0;
        for(int i = num; i <= 1000000; i += num) {
            if(hash[i - 1] - hash[prev + k] != 0) {
                return false;
            }
            prev = i;
        }
        return true;
    }

    void run() throws IOException{
        solve();
        out.close();
    }
    public static void main(String args[]) throws IOException{
        new Main().run();
    }
}
class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }
    public final int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
    }
    public long readLong() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String readString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return isWhitespace(c);
    }
        public double readDouble() {
        return Double.parseDouble(readString());
    }

    public static boolean isWhitespace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public String next() {
        return readString();
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}


import java.util.*;
import java.io.*;

public class Main{

    BufferedReader in;
    StringTokenizer str = null;
    PrintWriter out;

    private String next() throws Exception{
    	if (str == null || !str.hasMoreElements())
    	    str = new StringTokenizer(in.readLine());
    	return str.nextToken();
    }

    private int nextInt() throws Exception{
	   return Integer.parseInt(next());
    }

    final int N = 1000010;
    final int oo = Integer.MAX_VALUE/2;
    int []a, bit;

    public void run() throws Exception{
    	in = new BufferedReader(new InputStreamReader(System.in));
    	out = new PrintWriter(System.out);

        int n = nextInt(), k = nextInt();
        a = new int[n];
        int min = oo;
        int max = -oo;
        for(int i=0;i<n;i++) {
            a[i] = nextInt();
            min = Math.min(min, a[i]);
            max = Math.max(max, a[i]);
        }

        if (min <= k+1) {
            out.println(min);
            out.close();
            return;
        }

        bit = new int[N];
        for(int i=0;i<n;i++){
            update(a[i], 1);
        }

        for(int i=min;i>=k;i--){
            int p = max/i;
            if (max % i != 0) p++;
            int sum = 0;
            for(int j=1;j<=p && j*i<N;j++){
                sum+=sum(j*i, Math.min(j*i+k, N-1));
            }
            if (sum == n) {
                out.println(i);
                out.close();
                break;
            }
        }

        out.println(1);
        out.close();
    }

    private void update(int idx, int d) {
        while(idx < N) {
            bit[idx]+=d;
            idx+=idx&-idx;
        }
    }

    private int sum(int l, int r) {
        int prefix = 0;
        if (l > 0) prefix = sum(l-1);

        return sum(r) - prefix;
    }

    private int sum(int idx) {
        int ret = 0;
        while(idx > 0) {
            ret+=bit[idx];
            idx-=idx&-idx;
        }

        return ret;
    }

    public static void main(String args[]) throws Exception{
	   new Main().run();
    }
}


import java.util.*;
import java.io.*;

public class Main{

    BufferedReader in;
    StringTokenizer str = null;
    PrintWriter out;

    private String next() throws Exception{
    	if (str == null || !str.hasMoreElements())
    	    str = new StringTokenizer(in.readLine());
    	return str.nextToken();
    }

    private int nextInt() throws Exception{
	   return Integer.parseInt(next());
    }

    final int N = 1000010;
    final int oo = Integer.MAX_VALUE/2;
    int []a, b;
    //int []bit;
    int []tree;

    public void run() throws Exception{
    	in = new BufferedReader(new InputStreamReader(System.in));
    	out = new PrintWriter(System.out);

        int n = nextInt(), k = nextInt();
        a = new int[n];
        b = new int[N];
        int min = oo;
        int max = -oo;
        for(int i=0;i<n;i++) {
            a[i] = nextInt();
            b[a[i]] = 1;
            min = Math.min(min, a[i]);
            max = Math.max(max, a[i]);
        }

        if (min <= k+1) {
            out.println(min);
            out.close();
            return;
        }

        // bit = new int[N];
        // for(int i=0;i<n;i++){
        //     update(a[i], 1);
        // }

        tree = new int[4*N];
        build(1, 0, N-1);

        for(int i=min;i>=k;i--){
            int p = max/i;
            if (max % i != 0) p++;
            int sum = 0;
            for(int j=1;j<=p && j*i<N;j++){
                //sum+=sum(j*i, Math.min(j*i+k, N-1));
                sum+=sum(1, 0, N-1, j*i, Math.min(j*i+k, N-1));
            }
            if (sum == n) {
                out.println(i);
                out.close();
                break;
            }
        }

        out.println(1);
        out.close();
    }

    private void build(int v, int tl, int tr){
        if (tl == tr) {
            tree[v] = b[tl];
            return;
        }

        int tm = (tl + tr)/2;
        build(2*v, tl, tm);
        build(2*v+1, tm+1, tr);

        tree[v] = tree[2*v] + tree[2*v+1];
    }

    private int sum(int v,int tl, int tr, int l, int r) {
        if (l > r)
            return 0;
        if (tl == l && tr == r)
            return tree[v];

        int tm = (tl + tr)/2;
        int s1 = sum(2*v, tl, tm, l, Math.min(tm, r));
        int s2 = sum(2*v+1, tm+1, tr, Math.max(l, tm+1), r);

        return s1 + s2;
    }

    // private void update(int v, int tl, int tr, int pos, int d) {
    //     if (tl == tr) {
    //         tree[v] = d;
    //         return;
    //     }

    //     int tm = (tl + tr)/2;
    //     if (tm >= pos)
    //         update(2*v, tl, tm, pos, d);
    //     else
    //         update(2*v, tm+1, tr, pos, d);

    //     tree[v] = tree[2*v] + tree[2*v+1];
    // }

    // private void update(int idx, int d) {
    //     while(idx < N) {
    //         bit[idx]+=d;
    //         idx+=idx&-idx;
    //     }
    // }

    // private int sum(int l, int r) {
    //     int prefix = 0;
    //     if (l > 0) prefix = sum(l-1);

    //     return sum(r) - prefix;
    // }

    // private int sum(int idx) {
    //     int ret = 0;
    //     while(idx > 0) {
    //         ret+=bit[idx];
    //         idx-=idx&-idx;
    //     }

    //     return ret;
    // }

    public static void main(String args[]) throws Exception{
	   new Main().run();
    }
}


import java.util.*;
import java.io.*;

public class Main{

    BufferedReader in;
    StringTokenizer str = null;
    PrintWriter out;

    private String next() throws Exception{
    	if (str == null || !str.hasMoreElements())
    	    str = new StringTokenizer(in.readLine());
    	return str.nextToken();
    }

    private int nextInt() throws Exception{
	   return Integer.parseInt(next());
    }

    final int N = 1000010;
    final int oo = Integer.MAX_VALUE/2;
    int []a, bit;

    public void run() throws Exception{
    	in = new BufferedReader(new InputStreamReader(System.in));
    	out = new PrintWriter(System.out);

        int n = nextInt(), k = nextInt();
        a = new int[n];
        int min = oo;
        int max = -oo;
        for(int i=0;i<n;i++) {
            a[i] = nextInt();
            min = Math.min(min, a[i]);
            max = Math.max(max, a[i]);
        }

        if (min <= k+1) {
            out.println(min);
            out.close();
            return;
        }

        bit = new int[N];
        for(int i=0;i<n;i++){
            update(a[i], 1);
        }

        for(int i=min;i>=k;i--){
            int p = max/i;
            if (max % i != 0) p++;
            int sum = 0;
            for(int j=1;j<=p;j++){
                sum+=sum(j*i, Math.min(j*i+k, N-1));
            }
            if (sum == n) {
                out.println(i);
                out.close();
                break;
            }
        }

        out.println(1);
        out.close();
    }

    private void update(int idx, int d) {
        while(idx < N) {
            bit[idx]+=d;
            idx+=idx&-idx;
        }
    }

    private int sum(int l, int r) {
        int prefix = 0;
        if (l > 0) prefix = sum(l-1);

        return sum(r) - prefix;
    }

    private int sum(int idx) {
        int ret = 0;
        while(idx > 0) {
            ret+=bit[idx];
            idx-=idx&-idx;
        }

        return ret;
    }

    public static void main(String args[]) throws Exception{
	   new Main().run();
    }
}


import java.util.*;
import java.io.*;

public class Main {

	BufferedReader in;
	StringTokenizer str = null;
	PrintWriter out;

	private String next() throws Exception{
		if (str == null || !str.hasMoreElements())
			str = new StringTokenizer(in.readLine());
		return str.nextToken();
	}

	private int nextInt() throws Exception{
		return Integer.parseInt(next());
	}

	private long nextLong() throws Exception{
		return Long.parseLong(next());
	}

	private double nextDouble() throws Exception{
		return Double.parseDouble(next());
	}

	int n,k,c;
	int []b,a;
	int MAXA = 100010;

	public void run() throws Exception{
	    in =  new BufferedReader(new InputStreamReader(System.in));
	    out = new PrintWriter(System.out);
	    n = nextInt();
	    k = nextInt();

	    b = new int[n];
	    int min = Integer.MAX_VALUE/2;
	    int max = Integer.MIN_VALUE/2;
	    for(int i=0;i<n;i++){
		b[i] = nextInt();
		min = Math.min(b[i], min);
		max = Math.max(b[i], max);
	    }

	    if (min - 1 <= k){
		out.println(min);
		out.close();
		return;
	    }

	    c = 0;
	    int sum = 0;
	    while(1<<c < MAXA){
		sum+=1<<c;
		c++;
	    }
	    sum+=1<<c;
	    //System.out.println(sum + " " + (1<<c));
	    a = new int[sum+1];
	    init();
	    //System.out.println(Arrays.toString(a));
	    //System.out.println(sum(0, 1));
	    int l = k-1;
	    int r = min+1;

	    while(r - l > 1) {
		int m = (l + r)/2;
		sum = 0;
		for(int i=0;i<=max/m;i++){
		    //System.out.println((i*m) + " " + (i*m+k) + " " + sum(i*m, i*m+k));
		    sum+=sum(i * m, i * m + k);
		}
		//System.out.println(m + " " + sum);
		if (sum < n){
		    r = m;
		}else{
		    l = m;
		}
	    }

	    out.println(l);
	    out.close();
	}

	private void init(){
	    for(int i=0;i<n;i++){
		a[(1<<c) + b[i]] = 1;
	    }

	    for(int i=(1<<c)-1;i>0;i--){
		a[i] = a[2*i] + a[2*i+1];
	    }
	}

	private int sum(int l, int r) {
	    int ret = 0;
	    l+=1<<c;
	    r+=1<<c;
	    while(l <= r){
		if (l % 2 == 1){
		    ret+=a[l];
		    l++;
		}

		if (r % 2 == 0){
		    ret+=a[r];
		    r--;
		}

		l/=2;
		r/=2;
	    }

	    return ret;
	}

	public static void main(String[] args) throws Exception{
		new Main().run();
	}
}


import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class lead5
 {
  public static void main(String args[]) throws IOException
   {
    BufferedReader cin=new BufferedReader(new InputStreamReader(System.in));
      String s=cin.readLine();
      String tok[]=s.split(" ");
       int n=Integer.parseInt(tok[0]);
      int k=Integer.parseInt(tok[1]);
      s=cin.readLine();
      tok=s.split(" ");
       int bu[]=new int[n];
       for(int i=0;i<n;i++)
        {
          bu[i]=Integer.parseInt(tok[i]);
          }
      Arrays.sort(bu);
      int f=0;
      int u=bu[0];
      for(int i=0;i<n;i++)
        {
          f=bu[i]/u;
          if((bu[i]%u)<=k)
           ;
           else
            {
              u=bu[i]/(f+1);
              i=-1;
             }
          }
  System.out.println(u);
}
}


import java.util.*;
public class c {
public static void main(String[] args)
{
    Scanner input = new Scanner(System.in);
    int n = input.nextInt(), k = input.nextInt();
    int[] data = new int[n];
    for(int i = 0; i<n; i++) data[i] = input.nextInt();
    Arrays.sort(data);
    if(data[0] <= k+1) System.out.println(data[0]);
    else
    {
        int[] csum = new int[1000002];
        for(int i =0; i<n; i++) csum[data[i]]++;
        for(int i = 1; i<1000002; i++) csum[i] += csum[i-1];
        int res = k+1;
        for(int i = k+2; i<=data[0]; i++)
        {
            int count = 0;
            for(int j = 0; j<=1000000; j+= i)
            {
                count += csum[Math.min(j+k, 1000001)];
                count -= (j == 0 ? 0 : csum[j-1]);
            }
            if(count == n) res = Math.max(res, i);
        }
        System.out.println(res);
    }
}
}


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL unsigned long long
#define PI 3.1415926535897932626
typedef long long type;
using namespace std;
type gcd(type a, type b) {return b == 0 ? a : gcd(b, a % b);}
const int MAXN = 1000010;
const int INF = 0x3f3f3f3f;
int src[MAXN / 3];
int cnt[MAXN * 2];
int sum[MAXN * 2];
int N,K,MIN,MAX;

bool judge(int x)
{
    int limit = MAX / x;
    int tot = 0;
    for (int i = 1 ; i <= limit; i++)
    {
        tot += (sum[i * x + K] - sum[i * x - 1]);
        //if (x == 7) printf("%d %d %d %d\n",sum[i * x + K],sum[i * x - 1],i * x + K,i * x - 1);
    }
    return tot == N;
}

int main()
{
    scanf("%d%d",&N,&K);
    MIN = INF;MAX = -1;
    memset(cnt,0,sizeof(cnt));
    for (int i = 1 ;  i <= N ; i++)
    {
        scanf("%d",&src[i]);
        cnt[src[i]]++;
        MIN = min(src[i],MIN);
        MAX = max(src[i],MAX);
    }
    memset(sum,0,sizeof(sum));
    sum[MIN] = cnt[MIN];
    for (int i = MIN + 1 ; i < MAXN * 2; i++)
        sum[i] = sum[i - 1] + cnt[i];
    if (MIN <= K + 1) {printf("%d\n",MIN);return 0;}
    for (int i = MIN ; i >= K + 1 ; i--)
    {
        if (judge(i))
        {
            printf("%d\n",i);
            return 0;
        }
    }
    return 0;
}


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL unsigned long long
#define PI 3.1415926535897932626
typedef long long type;
using namespace std;
type gcd(type a, type b) {return b == 0 ? a : gcd(b, a % b);}
const int MAXN = 1000010;
const int INF = 0x3f3f3f3f;
int src[MAXN / 3];
int cnt[MAXN * 2];
int sum[MAXN * 2];
int N,K,MIN,MAX;

bool judge(int x)
{
    int limit = MAX / x;
    int cnt = 0;
    for (int i = 1 ; i <= limit + 1; i++)
    {
        cnt += (sum[i * x + K] - sum[i * x - 1]);
        //if (x == 7) printf("%d %d %d %d\n",sum[i * x + K],sum[i * x - 1],i * x + K,i * x - 1);
    }
    return cnt == N;
}

int main()
{
    while (scanf("%d%d",&N,&K) != EOF)
    {
        MIN = INF;MAX = -1;
        memset(cnt,0,sizeof(cnt));
        for (int i = 1 ;  i <= N ; i++)
        {
            scanf("%d",&src[i]);
            cnt[src[i]]++;
            MIN = min(src[i],MIN);
            MAX = max(src[i],MAX);
        }
        sum[MIN] = 1;
        for (int i = MIN + 1 ; i <= MAXN ; i++)
            sum[i] = sum[i - 1] + cnt[i];
        if (MIN <= K + 1) {printf("%d\n",MIN);continue;}
       // cout << MIN << " " << MAX << endl;
        for (int i = MIN ; i >= K + 1 ; i--)
        {
            if (judge(i))
            {
                printf("%d\n",i);
                return 0;
            }
        }
    }
    return 0;
}


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL unsigned long long
#define PI 3.1415926535897932626
typedef long long type;
using namespace std;
type gcd(type a, type b) {return b == 0 ? a : gcd(b, a % b);}
const int MAXN = 1000010;
const int INF = 0x3f3f3f3f;
int src[MAXN / 3];
int cnt[MAXN * 2];
int sum[MAXN * 2];
int N,K,MIN,MAX;

bool judge(int x)
{
    int limit = MAX / x;
    int cnt = 0;
    for (int i = 1 ; i <= limit; i++)
    {
        cnt += (sum[i * x + K] - sum[i * x - 1]);
        //if (x == 7) printf("%d %d %d %d\n",sum[i * x + K],sum[i * x - 1],i * x + K,i * x - 1);
    }
    return cnt == N;
}

int main()
{
    scanf("%d%d",&N,&K);
    {
        MIN = INF;MAX = -1;
        memset(cnt,0,sizeof(cnt));
        for (int i = 1 ;  i <= N ; i++)
        {
            scanf("%d",&src[i]);
            cnt[src[i]]++;
            MIN = min(src[i],MIN);
            MAX = max(src[i],MAX);
        }
        sum[MIN] = 1;
        for (int i = MIN + 1 ; i <= MAXN ; i++)
            sum[i] = sum[i - 1] + cnt[i];
        if (MIN <= K + 1) {printf("%d\n",MIN);return 0;}
       // cout << MIN << " " << MAX << endl;
        for (int i = MIN ; i >= K + 1 ; i--)
        {
            if (judge(i))
            {
                printf("%d\n",i);
                return 0;
            }
        }
    }
    return 0;
}


/* *********************************************************************
   *                       Problem: --------------                     *
   *                   Runtime: 0.000 sec; Rank: 0000                  *
   *                     Algo Used: ----------------                   *
   *                    Solved By : Niloy - JU-CSE-21                  *
   ********************************************************************* */
#include <bits/stdc++.h>                            //all pre-compiled header files
/* ********************
   *     Defines      *
   ******************** */
#define max(a,b) ((a>b)?a:b)                        //finding max
#define min(a,b) ((a<b)?a:b)                        //finding min
#define Max(a,b,c) max(a,max(b,c))                  //finding max between 3 numbers
#define Min(a,b,c) min(a,min(b,c))                  //finding min between 3 numbers
#define FOR(i,s,e) for(i=s;i<=e;i++)                //for loop with 1 increment
#define FORR(i,s,e) for(i=s;i>=e;i--)                //for loop with 1 increment
#define For(i,s,e,d) for(i=s;i<=e;i+=d)             //for loop with manual increment
#define _For(i,s,e,d) for(i=s;i>=e;i-=d)             //for loop with manual increment
#define Pi acos(-1.0)                               //defining Pi for mathematical uses
#define Clear(a) memset(a,0,sizeof(a))              //clearing memory of an array
#define setfalse(a) memset(a,false,sizeof(a))       //setting the array into false
#define settrue(a) memset(a,true,sizeof(a))         //setting the array into true
#define clrstr(a) memset(a,'\0',sizeof(a))          //setting string array to null
#define SET(a,i) memset(a,i,sizeof a)               //setting array to specefic value
#define open freopen("input.txt","r",stdin)         //opening input file
#define close freopen ("output.txt","w",stdout)     //opening output file
#define Case(a) printf("Case %d: ",a)               //printing case number
#define caseh(a) printf("Case #%d: ",a)             //printing case number having '#'
#define getcase(a) scanf("%d",&a)                   //scanning case number
#define S1(a) scanf("%d",&a)                        //scan one int
#define S2(a,b) scanf("%d%d",&a,&b)                 //scan two int
#define S3(a,b,c) scanf("%d%d%d",&a,&b,&c)          //scan three int
#define SL1(a) scanf("%lld",&a)                     //scanf one long long
#define SL2(a,b) scanf("%lld%lld",&a,&b)            //scanf two long long
#define SL3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)   //scanf two long long
#define CHR getchar()                               //avoid the newline character problem
#define caseloop(a,b) for(a=1;a<=b;a++)             //making case loop
#define EPS 1e-9                                    //small value for avoiding preccesion error
#define LL long long                                //long long short form
#define ULL unsigned long long                      //unsigned long long sort form
#define MX 10500                                    //MAX size/value
#define PB(x) push_back(x)                          //push in vector/string
#define PP pop_back()                               //pop from vector
#define PF(x) push_front(x)                         //push in vector/string/deque from front
#define PPF(x) pop_front()                          //pop from vector/deque from front
#define IN(x) insert(x)                             //insert element in set
#define PS(x) push(x)                               //push element in stack/queue
#define P() pop()                                   //pop element from stack/queue
#define SZ() size()                                 //return size
#define MOD 1000000007                              //mod value
#define INF (1<<28)                                 //infinity value
#define Y 1                                         //true value
#define N 0                                         //false value

using namespace std;

template <typename T> T BigMod (T b,T p,T m){if (p == 0) return 1;if (p%2 == 0){T s = BigMod(b,p/2,m);return ((s%m)*(s%m))%m;}return ((b%m)*(BigMod(b,p-1,m)%m))%m;}
template <typename T> T ModInv (T b,T m){return BigMod(b,m-2,m);}
template <typename T> void ia (T a[],int n){for (int i=0; i<n; i++) cin >> a[i];}
template <typename T> void pa (T a[],int n){for (int i=0; i<n-1; i++) cout << a[i] << " ";cout << a[n-1] << endl;}
template <typename T> T gcd(T a,T b){if (!b) return a;return gcd(b,a%b);}
template <typename T> T POW(T b,T p){if (p == 0) return 1;if (p%2 == 0){T s = POW(b,p/2);return s*s;}return b*POW(b,p-1);}

int tree[4*1000050];
bool vis[1000050];

void Insert(int idx,int l,int r,int val)
{
    if (l == r)
    {
        tree[idx] = val;
        return ;
    }

    int mid = (l+r)>>1, lft = idx<<1, rgt = lft|1;

    if (val<=mid)       Insert(lft,l,mid,val);
    else                Insert(rgt,mid+1,r,val);

    tree[idx] = max(tree[lft],tree[rgt]);
}

int Query(int idx,int l,int r,int st,int ed)
{
    //cout << l << "," << r << endl;
    if (st<=l && r<=ed)         return tree[idx];

    int mid = (l+r)>>1, lft = idx<<1, rgt = lft|1;

    if (ed<=mid)                return Query(lft,l,mid,st,ed);
    else if (st>mid)            return Query(rgt,mid+1,r,st,ed);
    else                        return max(Query(lft,l,mid,st,ed),Query(rgt,mid+1,r,st,ed));
}

int main()
{
    int a[100005];

    int n,k;

    int mx = -INF,mn = INF;

    int i;

    cin >> n >> k;

    FOR(i,0,n-1)
    {
        S1(a[i]);
        mn = min(mn,a[i]);
        mx = max(mx,a[i]);
        vis[a[i]] = 1;
    }

    FOR(i,1,1000000)         tree[i] = (vis[i]?i:tree[i-1]);

    FORR(i,mn,1)
    {
        int tmp = i;
        int dif = -INF;

        //cout << i << endl;

        while (tmp <= mx)
        {
            int Mx = tree[tmp+i-1];

            //cout << tmp << "->" << Mx << " & " << tmp << "->" << tmp+i-1 << endl;

            dif = max(dif,Mx-tmp);

            tmp += i;
        }

        //cout << endl;

        if (dif <= k)
        {
            break;
        }
    }
    cout << i << endl;

}