#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

struct MaxMatching{
	int N;
	VV<int> G;

	V<int> mate;

	void add_edge(int a,int b){
		if(a == b) return;
		G[a].pb(b);
		G[b].pb(a);
	}

	MaxMatching(int _N):N(_N),G(N){}

	using P = pair<int,int>;

	int maxMatching(){
		mate = V<int>(N+1,N);
		V<int> first(N+1,N),que(N);
		V<P> label(N+1,P(-1,-1));
		int qh = 0, qt = 0;

		auto enqueue = [&](int v){
			que[qt++] = v;
		};
		auto dequeue = [&](){
			return que[qh++];
		};

		function<void(int,int)> rematch = [&](int a, int b){
			int c = mate[a];
			mate[a] = b;
			if(mate[c] != a) return;
			if(label[a].sc == -1){
				mate[c] = label[a].fs;
				rematch(mate[c],c);
			}else{
				int x,y;
				tie(x,y) = label[a];
				rematch(x,y);
				rematch(y,x);
			}
		};
		auto relabel = [&](int a, int b){
			function<int(int)> findFirst = [&](int v){
				if(label[first[v]].fs < 0) return first[v];
				return first[v] = findFirst(first[v]);
			};
			int x = findFirst(a), y = findFirst(b);
			if(x == y) return;
			P h(~a,b);
			label[x] = label[y] = h;
			int join = -1;
			while(true){
				if(y != N) swap(x,y);
				x = findFirst(label[mate[x]].fs);
				if(label[x] == h){
					join = x;
					break;
				}else{
					label[x] = h;
				}
			}
			for(int v: {first[a],first[b]}){
				for(;v != join; v = first[label[mate[v]].fs]){
					label[v] = P(a,b);
					first[v] = join;
					enqueue(v);
				}
			}
		};
		auto augment = [&](int s){
			label[s] = P(N,-1);
			first[s] = N;
			qh = qt = 0;
			enqueue(s);
			while(qh != qt){
				int a = dequeue();
				for(int b: G[a]){
					if(mate[b] == N && b != s){
						mate[b] = a;
						rematch(a,b);
						return true;
					}else if(label[b].fs >= 0){
						relabel(a,b);
					}else if(label[mate[b]].fs == -1){
						label[mate[b]].fs = a;
						first[mate[b]] = b;
						enqueue(mate[b]);
					}
				}
			}
			return false;
		};

		int numMatch = 0;
		rep(v,N){
			if(mate[v]<N || !augment(v)) continue;
			numMatch++;
			rep(i,qt){		// including popped !!
				int v = que[i];
				label[v] = label[mate[v]] = P(-1,-1);
			}
			label[N] = P(-1,-1);
		}
		mate.pop_back();
		rep(i,N) if(mate[i] == N) mate[i] = -1;
		return numMatch;
	}
};

ll brute(V<ll> a,ll M){
	int N = a.size()/2;
	ll lb = -1, ub = M-1;
	auto can = [&](ll X){
		MaxMatching MM(N*2);
		rep(i,N*2) rep(j,i){
			if((a[i]+a[j])%M <= X) MM.add_edge(i,j);
		}
		return MM.maxMatching() == N;
	};
	while(ub-lb>1){
		ll m = (ub+lb)/2;
		if(can(m)) ub = m;
		else lb = m;
	}
	return ub;
}
ll solve(V<ll> a, ll M){
	int N = a.size()/2;
	auto f = [&](int i,int j){
		return (a[i]+a[j])%M;
	};
	auto allover = [&](int L){
		rep(i,N-L){
			if(a[L+L+i]+a[N+N-1-i] < M) return false;
		}
		return true;
	};
	int lb = -1, ub = N;
	while(ub-lb>1){
		int m = (lb+ub)/2;
		if(allover(m)) ub = m;
		else lb = m;
	}

	int L = ub;
	ll mx = 0;
	rep(i,L) chmax(mx,f(i,L+L-1-i));
	rep(i,N-L) chmax(mx,f(L+L+i,N+N-1-i));
	return mx;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N;
	ll M;
	cin >> N >> M;
	V<ll> a(N*2);
	rep(i,N*2) cin >> a[i];
	sort(all(a));
//	int god = brute(a,M);
	int ans = solve(a,M);
//	show(god);
	show(ans);
//	assert(god == ans);
	cout << ans << endl;

}


Measured memory_bytes: 3328